diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2016-03-26 13:50:43 +0100 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2016-03-26 13:50:43 +0100 |
commit | d62c8c002c51fb7c36487839eeeb4ac89f044dee (patch) | |
tree | bb4d1f5c631ab1f22a3018ba39e6a806035f80fd /part | |
download | kxmleditor-d62c8c002c51fb7c36487839eeeb4ac89f044dee.tar.gz kxmleditor-d62c8c002c51fb7c36487839eeeb4ac89f044dee.zip |
Initial import of kxmleditor 1.1.4
Diffstat (limited to 'part')
162 files changed, 15832 insertions, 0 deletions
diff --git a/part/Makefile.am b/part/Makefile.am new file mode 100644 index 0000000..3a1e59a --- /dev/null +++ b/part/Makefile.am @@ -0,0 +1,53 @@ +####### kdevelop will overwrite this part!!! (begin)########## + +lib_LTLIBRARIES = libkxmleditorpart.la + +libkxmleditorpart_la_SOURCES = kxesearchdialogbase.ui kxesearchdialog.cpp kxeprocinstrdialogbase.ui kxeprocinstrdialog.cpp kxespecprocinstrdialogbase.ui kxespecprocinstrdialog.cpp kxeelementdialogbase.ui kxeelementdialog.cpp kxeattributedialogbase.ui kxeattributedialog.cpp kxechardatadialogbase.ui kxechardatadialog.cpp kxeattachdialogbase.ui kxechoosestringdialogbase.ui kxechoosestringdialog.cpp kxefilenewdialog.cpp kxeconfiguration.cpp kxesettings.cpp kxetreeviewsettingspage.ui kxetreeviewsettings.cpp kxenewfilesettingspage.ui kxenewfilesettings.cpp kxeprintsettingspage.ui kxeprintsettings.cpp kxearchiveextssettingspage.ui kxearchiveextssettings.cpp kxetextviewsettingspage.ui kxetextviewsettings.cpp kxe_treeviewitem.cpp kxe_treeview.cpp kxe_viewelement.cpp kxe_viewattributes.cpp kxesyntaxhighlighter.cpp kxetexteditordialogbase.ui kxetexteditordialog.cpp actions.cpp qdom_add.cpp kxecommand.cpp commands_file.cpp commands_edit.cpp commands_insert.cpp kxmleditorpart.cpp kxmleditorfactory.cpp dcopiface_part_ro.skel dcopiface_part_ro.cpp kxedocument.cpp + +libkxmleditorpart_la_LDFLAGS = -module $(all_libraries) -version-info 1:0:0 +libkxmleditorpart_la_LIBADD = $(LIB_KDEPRINT) $(LIB_KPARTS) $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) + +SUBDIRS = pics icons + +EXTRA_DIST = kxmleditorpartBrowseUI.rc kxmleditorpartEditUI.rc kxedocument.rc kxmleditorpart.desktop + + +install-data-local: + $(mkinstalldirs) $(kde_servicesdir) + $(INSTALL_DATA) $(srcdir)/kxmleditorpart.desktop $(kde_servicesdir)/kxmleditorpart.desktop + +uninstall-local: + -rm -f $(kde_servicesdir)/kxmleditorpart.desktop + -rmdir $(kde_servicesdir) + +####### 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 = kxmleditorpartBrowseUI.rc kxmleditorpartEditUI.rc kxedocument.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 = kxesearchdialog.h kxeprocinstrdialog.h kxespecprocinstrdialog.h kxeelementdialog.h kxeattributedialog.h kxechardatadialog.h kxechoosestringdialog.h kxefilenewdialog.h kxeconfiguration.h kxesettings.h kxetreeviewsettings.h kxenewfilesettings.h kxeprintsettings.h kxearchiveextssettings.h kxetextviewsettings.h kxe_treeviewitem.h kxe_treeview.h kxe_viewelement.h kxe_viewattributes.h kxesyntaxhighlighter.h kxetexteditordialog.h actions.h qdom_add.h kxecommand.h commands_file.h commands_edit.h commands_insert.h kxmleditorabout.h kxmleditorpart.h kxmleditorfactory.h dcopiface_part_ro.h kxedocument.h diff --git a/part/actions.cpp b/part/actions.cpp new file mode 100644 index 0000000..8b6abcb --- /dev/null +++ b/part/actions.cpp @@ -0,0 +1,229 @@ +/*************************************************************************** + actions.cpp - description + ------------------- + begin : Tue Jul 10 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 "actions.h" + +// include files for QT + +#include <qwhatsthis.h> +#include <qdragobject.h> +#include <qcombobox.h> +#include <qapplication.h> + +// include files for KDE +#include <ktoolbar.h> +#include <kiconloader.h> +#include <kmimetype.h> +#include <kdebug.h> + +//------------------------------------------------------------------- +// +// KXmlEditorComboAction member functions +// +//------------------------------------------------------------------- + +KXmlEditorComboAction::KXmlEditorComboAction(const QString& text, + int accel, + const QObject *receiver, + const char *member, + QObject* parent, + const char* name) + : KAction(text, accel, parent, name), + m_pCombo(0) +{ + m_receiver = receiver; + m_member = member; +} + +KXmlEditorComboAction::~KXmlEditorComboAction() +{ + //delete m_pCombo; // L.V. this cause crash !!! +} + +QComboBox* KXmlEditorComboAction::comboBox() +{ + return m_pCombo; +} + +int KXmlEditorComboAction::plug(QWidget *w, int index) +{ + // if ( !w->inherits( "KToolBar" ) ); + // return -1; + + KToolBar *toolBar = (KToolBar *) w; + + int id = KAction::getToolButtonID(); + //kdDebug() << "KXmlEditorComboAction::plug id=" << id << endl; + + m_pCombo = new QComboBox( toolBar, "Path Combo" ); + m_pCombo->setEditable(true); + m_pCombo->setInsertionPolicy(QComboBox::NoInsertion); + toolBar->insertWidget( id, 70, m_pCombo, index ); + connect( m_pCombo, SIGNAL(activated(const QString&)), m_receiver, m_member ); + + addContainer( toolBar, id ); + + connect(toolBar, SIGNAL(destroyed()), this, SLOT(slotDestroyed())); + + toolBar->setItemAutoSized(id, true); + + QWhatsThis::add( m_pCombo, whatsThis() ); + + return containerCount() - 1; +} + +void KXmlEditorComboAction::unplug(QWidget *w) +{ +// if ( !w->inherits( "KToolBar" ) ) +// return; + + KToolBar *toolBar = (KToolBar *)w; + + int idx = findContainer( w ); + //kdDebug() << "KXmlEditorComboAction::unplug idx=" << idx << " menuId=" << menuId(idx) << endl; + + toolBar->removeItem( menuId( idx ) ); + + removeContainer( idx ); + m_pCombo = 0; +} + +void KXmlEditorComboAction::slotClear() +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::slotClear] action not plugged" << endl; + return; + } + + m_pCombo->clear(); +} + +void KXmlEditorComboAction::slotClearEdit() +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::slotClearEdit] action not plugged" << endl; + return; + } + + m_pCombo->clearEdit(); +} + +void KXmlEditorComboAction::slotFocusEdit() +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::slotFocusEdit] action not plugged" << endl; + return; + } + + m_pCombo->setFocus(); +} + +QString KXmlEditorComboAction::currentText() const +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::currentText] action not plugged" << endl; + return QString::null; + } + + return m_pCombo->currentText(); +} + +const QPixmap * KXmlEditorComboAction::currentPixmap() const +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::currentPixmap] action not plugged" << endl; + return 0; + } + + return m_pCombo->pixmap( m_pCombo->currentItem() ); +} + +void KXmlEditorComboAction::insertItem( const QPixmap & pixmap, const QString & text ) +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::insertItem] action not plugged" << endl; + return; + } + + if ( text.isEmpty() ) + kdWarning() << "[KXmlEditorComboAction::insertItem] empty string as parameter" << endl; + + int nIndex = findItem(text); + if ( nIndex != -1 ) + m_pCombo->removeItem(nIndex); + + m_pCombo->insertItem( pixmap, text, 0 ); + m_pCombo->setCurrentItem(0); + + if ( m_pCombo->count() > 15 ) + m_pCombo->removeItem(15); +} + +void KXmlEditorComboAction::removeItem( const QString & text ) +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::removeItem] action not plugged" << endl; + return; + } + + int nIndex = findItem(text); + if ( nIndex == -1 ) + { + kdDebug() << "KXmlEditorComboAction::removeItem] item not found" << endl; + return; + } + + m_pCombo->removeItem(nIndex); +} + +int KXmlEditorComboAction::findItem( const QString & text ) +{ + if ( containerCount() == 0 ) + { + kdWarning() << "[KXmlEditorComboAction::findItem] action not plugged" << endl; + return -1; + } + + int nIndex = -1; + int i=0; + while ( ( i < m_pCombo->count() ) && ( nIndex == -1 ) ) + { + if ( m_pCombo->text(i) == text ) + nIndex = i; + i++; + } + + return nIndex; +} + +ToolbarLabel::ToolbarLabel( const QString& text ) + : QLabel( text, 0L, "kde toolbar widget" ) // Use this name for it to be styled! +// , m_mw(mw) +{ + setBackgroundMode( Qt::PaletteButton ); + setAlignment( (QApplication::reverseLayout() ? Qt::AlignRight : Qt::AlignLeft) | + Qt::AlignVCenter | Qt::ShowPrefix ); + adjustSize(); + } + diff --git a/part/actions.h b/part/actions.h new file mode 100644 index 0000000..43d0967 --- /dev/null +++ b/part/actions.h @@ -0,0 +1,88 @@ +/*************************************************************************** + actions.h - description + ------------------- + begin : Tue Jul 10 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 ACTIONS_H +#define ACTIONS_H + +#include <kaction.h> +#include <qlabel.h> +class QComboBox; + +/** + *@author Lumir Vanek + */ + +class KXmlEditorComboAction : public KAction +{ + Q_OBJECT +public: + KXmlEditorComboAction(const QString& text, int accel, const QObject *receiver, const char *member, QObject* parent, const char* name); + ~KXmlEditorComboAction(); + + virtual int plug(QWidget *w, int index = -1); + + virtual void unplug(QWidget *w); + + /** Returns the text from the combobox' editline (@ref QComboBox::currentText). */ + QString currentText() const; + + /** Returns the current pixmap or 0, if there isn't any (see @ref QComboBox::pixmap). */ + const QPixmap * currentPixmap() const; + + /** + * Inserts the given item as the first. + * Deletes the old entry, if the item was already in the list. + */ + void insertItem( const QPixmap & pixmap, const QString & text ); + + /** Tries to remove the item with the given text. */ + void removeItem( const QString & text ); + + /** returns combo box */ + QComboBox *comboBox(); + +public slots: + /** Clears the whole combobox using @ref QComboBox::clear. */ + void slotClear(); + /** Clears the combobox' editline. */ + void slotClearEdit(); + /** Gives focus to the combobox' editline. */ + void slotFocusEdit(); + +protected: + /** + * Tries to find an item with the given text. If it finds it, + * the items id is returned, otherwise -1. + */ + virtual int findItem( const QString & text ); + +private: + const QObject *m_receiver; + const char *m_member; + QComboBox * m_pCombo; +}; + + +class ToolbarLabel : public QLabel +{ + Q_OBJECT +public: + ToolbarLabel( const QString & text ); +}; + + +#endif diff --git a/part/commands_edit.cpp b/part/commands_edit.cpp new file mode 100644 index 0000000..ba298b0 --- /dev/null +++ b/part/commands_edit.cpp @@ -0,0 +1,778 @@ +/*************************************************************************** + commands_edit - description + ------------------- + begin : Wed Nov 26 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : a_charytoniuk@user.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 "commands_edit.h" + +#include <kdebug.h> + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Cutting element to clipboard ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXECutCommand::KXECutCommand(KXEDocument *pDocument, QDomNode &domNode) + : KXEDeleteNodeCommand(pDocument, domNode) +{ +} + +KXECutCommand::~KXECutCommand() +{ +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Pasting node from clipboard to document ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEPasteToDocumentCommand::KXEPasteToDocumentCommand( + KXEDocument *pDocument, + QDomDocument *pDomTargetDoc, + QDomElement &domSourceElement + ) + : KXECommand(pDocument) +{ + if ( pDomTargetDoc == 0 ) + kdError() << "KXEPasteToDocumentCommand::KXEPasteToDocumentCommand the given XML document object is empty." << endl; + + m_pDomTargetDoc = pDomTargetDoc; + m_domSourceElement = domSourceElement; +} + +KXEPasteToDocumentCommand::~KXEPasteToDocumentCommand() +{ +} + +void KXEPasteToDocumentCommand::execute() +{ + // Insert root element + QDomNode newNode = m_pDomTargetDoc->importNode(m_domSourceElement, true); + m_pDomTargetDoc->appendChild(newNode); + m_pDocument->updateNodeCreated(newNode); +} + +void KXEPasteToDocumentCommand::unexecute() +{ + QDomNode removedNode = m_pDomTargetDoc->removeChild( m_pDomTargetDoc->documentElement()); + + if ( removedNode.isNull() ) + kdError() << "KXEPasteToDocumentCommand::unexecute error removing node." << endl; + else + { + m_pDocument->updateNodeDeleted(removedNode); + } +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Pasting node from clipboard to element ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEPasteToElementCommand::KXEPasteToElementCommand( + KXEDocument *pDocument, + QDomElement & domTargetElement, + QDomNode &domSourceNode + ) + : KXECommand(pDocument) +{ + if ( domTargetElement.isNull() ) + kdError() << "KXEPasteCommand::KXEPasteCommand the given XML element object is empty." << endl; + + m_domTargetElement = domTargetElement; + m_domSourceNode = domSourceNode; +} + +KXEPasteToElementCommand::~KXEPasteToElementCommand() +{ +} + +void KXEPasteToElementCommand::execute() +{ + m_domTargetElement.appendChild(m_domSourceNode); + m_pDocument->updateNodeCreated(m_domSourceNode); +} + +void KXEPasteToElementCommand::unexecute() +{ + if ( m_domSourceNode.parentNode().removeChild( m_domSourceNode ).isNull() ) + kdError() << "KXEPasteToElementCommand::unexecute error removing the node." << endl; + else + { + m_pDocument->updateNodeDeleted(m_domSourceNode); + } +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Pasting proc.instr from clipboard to proc.instr ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEPasteToProcInstrCommand::KXEPasteToProcInstrCommand( + KXEDocument *pDocument, + QDomProcessingInstruction &domTargetProcInstr, + QDomProcessingInstruction &domSourceProcInstr + ) + : KXECommand(pDocument) +{ + if ( domTargetProcInstr.isNull() ) + kdError() << "KXEPasteToProcInstrCommand::KXEPasteToProcInstrCommand the given object is empty." << endl; + + if ( domSourceProcInstr.isNull() ) + kdError() << "KXEPasteToProcInstrCommand::KXEPasteToProcInstrCommand the given object is empty." << endl; + + m_domTargetProcInstr = domTargetProcInstr; + m_strNewData = domSourceProcInstr.data(); +} + +KXEPasteToProcInstrCommand::~KXEPasteToProcInstrCommand() +{ +} + +void KXEPasteToProcInstrCommand::execute() +{ + // Replace contents of selected proc. instr. + m_strOldData = m_domTargetProcInstr.data(); + m_domTargetProcInstr.setData(m_strNewData); + m_pDocument->updateNodeChanged(m_domTargetProcInstr); +} + +void KXEPasteToProcInstrCommand::unexecute() +{ + // Rverse action. + m_domTargetProcInstr.setData(m_strOldData); + m_pDocument->updateNodeChanged(m_domTargetProcInstr); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Pasting char. data from clipboard to char. data ////////// +////////////////////////////////////////////////////////////////////////////////////////// + + +KXEPasteToCharDataCommand::KXEPasteToCharDataCommand( + KXEDocument *pDocument, + QDomCharacterData &domTargetCharData, + QDomCharacterData &domSourceCharData + ) + : KXECommand(pDocument) +{ + if ( domTargetCharData.isNull() ) + kdError() << "KXEPasteToCharDataCommand::KXEPasteToCharDataCommand the given object is empty." << endl; + + if ( domSourceCharData.isNull() ) + kdError() << "KXEPasteToCharDataCommand::KXEPasteToCharDataCommand the given object is empty." << endl; + + m_domTargetCharData = domTargetCharData; + m_strNewData = domSourceCharData.data(); +} + +KXEPasteToCharDataCommand::~KXEPasteToCharDataCommand() +{ +} + +void KXEPasteToCharDataCommand::execute() +{ + // replace target contents with source + m_strOldData = m_domTargetCharData.data(); + m_domTargetCharData.setData(m_strNewData); + m_pDocument->updateNodeChanged(m_domTargetCharData); +} + +void KXEPasteToCharDataCommand::unexecute() +{ + m_domTargetCharData.setData(m_strOldData); + m_pDocument->updateNodeChanged(m_domTargetCharData); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Drag & drop node ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEDragDropMoveCommand::KXEDragDropMoveCommand( + KXEDocument *pDocument, + QDomElement & domTargetElement, + QDomNode &domSourceNode + ) + : KXECommand(pDocument) +{ + if ( domTargetElement.isNull() ) + kdError() << "KXEDragDropMoveCommand::KXEDragDropMoveCommand the given XML element object is empty." << endl; + + m_domTargetElement = domTargetElement; + m_domSourceNode = domSourceNode; + m_domPreviousParentNode = m_domSourceNode.parentNode(); +} + +KXEDragDropMoveCommand::~KXEDragDropMoveCommand() +{ +} + +void KXEDragDropMoveCommand::execute() +{ + // 1st, remove source node from its parent + if( m_domPreviousParentNode.removeChild( m_domSourceNode ).isNull() ) + kdError() << "KXEDocument::slotXmlElementDelete error removing the selected node." << endl; + else + m_pDocument->updateNodeDeleted(m_domSourceNode); + + // 2nd, append moved node to new parent + m_domTargetElement.appendChild(m_domSourceNode); + m_pDocument->updateNodeCreated(m_domSourceNode); +} + +void KXEDragDropMoveCommand::unexecute() +{ + // 1st, remove source node from its parent + if ( m_domTargetElement.removeChild( m_domSourceNode ).isNull() ) + kdError() << "KXEPasteToElementCommand::unexecute error removing the node." << endl; + else + { + m_pDocument->updateNodeDeleted(m_domSourceNode); + } + + // 2nd, append moved node to previous parent + m_domPreviousParentNode.appendChild(m_domSourceNode); + m_pDocument->updateNodeCreated(m_domSourceNode); +} + + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Deleting node ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEDeleteNodeCommand::KXEDeleteNodeCommand(KXEDocument *pDocument, QDomNode &domNode) + : KXECommand(pDocument) +{ + m_domNode = domNode; + m_domParentNode = m_domNode.parentNode(); + m_afterNode = m_domNode.previousSibling(); + + if ( m_domParentNode.isNull() ) + kdError() << "KXEDeleteNodeCommand::KXEDeleteNodeCommand selected nodes parent node is empty." << endl; +} + +KXEDeleteNodeCommand::~KXEDeleteNodeCommand() +{ +} + +void KXEDeleteNodeCommand::execute() +{ + if ( m_domParentNode.removeChild( m_domNode ).isNull() ) + kdError() << "KXEDeleteNodeCommand::execute error removing the selected node." << endl; + else + { + m_pDocument->updateNodeDeleted(m_domNode); + } +} + +void KXEDeleteNodeCommand::unexecute() +{ + if (m_afterNode.isNull()) + m_domParentNode.insertBefore(m_domNode,m_afterNode); + else + m_domParentNode.insertAfter( m_domNode,m_afterNode ); + m_pDocument->updateNodeCreated(m_domNode); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Deleting one attribute ////////// +////////////////////////////////////////////////////////////////////////////////////////// + + +KXEDeleteAttrCommand::KXEDeleteAttrCommand( + KXEDocument *pDocument, + QDomElement &domOwnerElement, + QDomAttr &domAttr + ) + : KXECommand(pDocument) +{ + m_domOwnerElement = domOwnerElement; + m_domAttr = domAttr; +} + +KXEDeleteAttrCommand::~KXEDeleteAttrCommand() +{ +} + +void KXEDeleteAttrCommand::execute() +{ + m_domOwnerElement.removeAttributeNode(m_domAttr); + m_pDocument->updateNodeChanged(m_domOwnerElement); +} + +void KXEDeleteAttrCommand::unexecute() +{ + m_domOwnerElement.setAttributeNode( m_domAttr ); + m_pDocument->updateNodeChanged( m_domOwnerElement ) ; +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Deleting all attributes ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEDeleteAllAttribCommand::KXEDeleteAllAttribCommand( + KXEDocument *pDocument, + QDomElement &domOwnerElement + ) + : KXECommand(pDocument) +{ + m_domOwnerElement = domOwnerElement; + m_listRemovedAttributes.setAutoDelete( true ); // the list owns the objects +} + +KXEDeleteAllAttribCommand::~KXEDeleteAllAttribCommand() +{ +} + +void KXEDeleteAllAttribCommand::execute() +{ + QDomNamedNodeMap mapAttributes = m_domOwnerElement.attributes(); + uint nAttributes = mapAttributes.count(); + + if( nAttributes == 0 ) + return; + + for( uint nRow = nAttributes; nRow > 0; nRow-- ) + { + QDomNode node = mapAttributes.item(nRow-1); + if ( node.isAttr() ) + { QDomAttr domAttr = node.toAttr(); + + QDomAttr *pNodeCloned = new QDomAttr(domAttr.cloneNode(true).toAttr()); + + m_listRemovedAttributes.append(pNodeCloned); + m_domOwnerElement.removeAttributeNode(node.toAttr()); + } + else + kdDebug() << "KXMLEditor " << k_funcinfo << " node is not an attribute (but should be)" << node.nodeName() << endl; + } + + m_pDocument->updateNodeChanged(m_domOwnerElement); +} + +void KXEDeleteAllAttribCommand::unexecute() +{ + QDomNamedNodeMap mapAttributes = m_domOwnerElement.attributes(); + uint nAttributes = m_listRemovedAttributes.count(); + + if ( nAttributes == 0 ) + return; + + QDomAttr *pDomAttr; + for ( pDomAttr = m_listRemovedAttributes.first(); pDomAttr; pDomAttr = m_listRemovedAttributes.next() ) + { + if(!pDomAttr->namespaceURI().isEmpty()) + m_domOwnerElement.setAttribute(pDomAttr->name(), pDomAttr->value()); + else + m_domOwnerElement.setAttributeNS(pDomAttr->namespaceURI(), pDomAttr->name(), pDomAttr->value()); + } + + m_listRemovedAttributes.clear(); + + m_pDocument->updateNodeChanged(m_domOwnerElement); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Moving node up ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEUpCommand::KXEUpCommand(KXEDocument *pDocument, QDomNode &domNode) + : KXECommand(pDocument) +{ + m_domNode = domNode; + m_domParentNode = m_domNode.parentNode(); + + if ( m_domParentNode.isNull() ) + kdError() << "KXEUpCommand::KXEUpCommand selected nodes parent node is empty." << endl; +} + +KXEUpCommand::~KXEUpCommand() +{ +} + +void KXEUpCommand::execute() +{ + QDomNode domPrevSibling = m_domNode.previousSibling(); + if ( domPrevSibling.isNull() ) + { + kdError() << "KXEUpCommand::execute selected node doesn't seem to have a previous sibling." << endl; + return; + } + + QDomNode domNode = m_domParentNode.removeChild( m_domNode ); + if ( domNode.isNull() ) + kdError() << "KXEUpCommand::execute can't remove child node." << endl; + else + { + domNode = m_domParentNode.insertBefore( domNode, domPrevSibling ); + if ( domNode.isNull() ) + kdError() << "KXEUpCommand::execute can't insert child node." << endl; + else + { + m_pDocument->updateNodeMoved(domNode); + } + } +} + +void KXEUpCommand::unexecute() +{ + QDomNode domNextSibling = m_domNode.nextSibling(); + if ( domNextSibling.isNull() ) + { + kdError() << "KXEUpCommand::unexecute selected node doesn't seem to have a next sibling." << endl; + return; + } + + QDomNode domNode = m_domParentNode.removeChild( m_domNode ); + if ( domNode.isNull() ) + kdError() << "KXEUpCommand::unexecute can't remove child node." << endl; + else + { + domNode = m_domParentNode.insertAfter( domNode, domNextSibling ); + if ( domNode.isNull() ) + kdError() << "KXEUpCommand::unexecute can't insert child node." << endl; + else + { + m_pDocument->updateNodeMoved(domNode); + } + } +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Moving node down ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEDownCommand::KXEDownCommand(KXEDocument *pDocument, QDomNode &domNode) + : KXECommand(pDocument) +{ + m_domNode = domNode; + m_domParentNode = m_domNode.parentNode(); + + if ( m_domParentNode.isNull() ) + kdError() << "KXEDownCommand::KXEDownCommand selected nodes parent node is empty." << endl; +} + +KXEDownCommand::~KXEDownCommand() +{ +} + +void KXEDownCommand::execute() +{ + QDomNode domNextSibling = m_domNode.nextSibling(); + if ( domNextSibling.isNull() ) + { + kdError() << "KXEDownCommand::execute selected node doesn't seem to have a next sibling." << endl; + return; + } + + QDomNode domNode = m_domParentNode.removeChild( m_domNode ); + if ( domNode.isNull() ) + kdError() << "KXEDownCommand::execute can't remove child node." << endl; + else + { + domNode = m_domParentNode.insertAfter( domNode, domNextSibling ); + if ( domNode.isNull() ) + kdError() << "KXEDownCommand::execute can't insert child node." << endl; + else + { + m_pDocument->updateNodeMoved(domNode); + } + } +} + +void KXEDownCommand::unexecute() +{ + QDomNode domPrevSibling = m_domNode.previousSibling(); + if ( domPrevSibling.isNull() ) + { + kdError() << "KXEDownCommand::unexecute selected node doesn't seem to have a previous sibling." << endl; + return; + } + + QDomNode domNode = m_domParentNode.removeChild( m_domNode ); + if ( domNode.isNull() ) + kdError() << "KXEDownCommand::unexecute can't remove child node." << endl; + else + { + domNode = m_domParentNode.insertBefore( domNode, domPrevSibling ); + if ( domNode.isNull() ) + kdError() << "KXEDownCommand::unexecute can't insert child node." << endl; + else + { + m_pDocument->updateNodeMoved(domNode); + } + } +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Editing char. data properties ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEEditCharDataCommand::KXEEditCharDataCommand( + KXEDocument *pDocument, + QDomCharacterData &domCharacterData, + const QString strNewContents + ) + : KXECommand(pDocument) +{ + m_domCharacterData = domCharacterData; + m_strNewContents = strNewContents; +} + +KXEEditCharDataCommand::~KXEEditCharDataCommand() +{ +} + +void KXEEditCharDataCommand::execute() +{ + m_strOldContents = m_domCharacterData.data(); + m_domCharacterData.setData( m_strNewContents ); + m_pDocument->updateNodeChanged( m_domCharacterData ); +} + +void KXEEditCharDataCommand::unexecute() +{ + m_domCharacterData.setData( m_strOldContents ); + m_pDocument->updateNodeChanged( m_domCharacterData ); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Editing proc. instr properties ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEEditProcInstrCommand::KXEEditProcInstrCommand( + KXEDocument *pDocument, + QDomProcessingInstruction &domProcInstr, + const QString strNewData + ) + : KXECommand(pDocument) +{ + m_domProcInstr = domProcInstr; + m_strNewData = strNewData; +} + +KXEEditProcInstrCommand::~KXEEditProcInstrCommand() +{ +} + +void KXEEditProcInstrCommand::execute() +{ + m_strOldData = m_domProcInstr.data(); + m_domProcInstr.setData( m_strNewData ); + m_pDocument->updateNodeChanged( m_domProcInstr ); +} + +void KXEEditProcInstrCommand::unexecute() +{ + m_domProcInstr.setData( m_strOldData ); + m_pDocument->updateNodeChanged( m_domProcInstr ); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Editing element data properties ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEEditElementCommand::KXEEditElementCommand( + KXEDocument *pDocument, + QDomElement &domElement, + const QString strNewPrefix, + const QString strNewName + ) + : KXECommand(pDocument) +{ + m_domElement = domElement; + m_strNewPrefix = strNewPrefix; + m_strNewName = strNewName; +} + +KXEEditElementCommand::~KXEEditElementCommand() +{ +} + +void KXEEditElementCommand::execute() +{ + m_strOldPrefix = m_domElement.prefix(); + m_strOldName = m_domElement.tagName(); + + + if ( ! m_domElement.namespaceURI().isNull() ) + m_domElement.setPrefix( m_strNewPrefix ); + + m_domElement.setTagName( m_strNewName ); + + m_pDocument->updateNodeChanged( m_domElement ); +} + +void KXEEditElementCommand::unexecute() +{ + if ( ! m_domElement.namespaceURI().isNull() ) + m_domElement.setPrefix( m_strOldPrefix ); + + m_domElement.setTagName( m_strOldName ); + + m_pDocument->updateNodeChanged( m_domElement ); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Edit attribute value ////////// +////////////////////////////////////////////////////////////////////////////////////////// + + +KXEEditAttrValueCommand::KXEEditAttrValueCommand( + KXEDocument *pDocument, + const QDomAttr &domAttr, + const QString strNewValue + ) + : KXECommand(pDocument) +{ + m_domAttr = domAttr; + m_strNewValue = strNewValue; +} + +KXEEditAttrValueCommand::~KXEEditAttrValueCommand() +{ +} + +void KXEEditAttrValueCommand::execute() +{ + m_strOldValue = m_domAttr.value(); + m_domAttr.setValue( m_strNewValue ); + + m_pDocument->updateNodeChanged(m_domAttr.ownerElement()); +} + +void KXEEditAttrValueCommand::unexecute() +{ + m_domAttr.setValue( m_strOldValue ); + + m_pDocument->updateNodeChanged(m_domAttr.ownerElement()); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Edit attribute name ////////// +////////////////////////////////////////////////////////////////////////////////////////// + + +KXEEditAttrNameCommand::KXEEditAttrNameCommand( + KXEDocument *pDocument, + const QDomAttr &domOldAttr, + const QString strNewName + ) + : KXECommand(pDocument) +{ + m_strNewName = strNewName; + m_strOldName = domOldAttr.name(); + m_strValue = domOldAttr.value(); + + if(!domOldAttr.namespaceURI().isEmpty()) + m_strNamespaceURI = domOldAttr.namespaceURI(); + + m_domOwnerElement = domOldAttr.ownerElement(); +} + +KXEEditAttrNameCommand::~KXEEditAttrNameCommand() +{ +} + +void KXEEditAttrNameCommand::execute() +{ + // it's not possible to change name. Must delete attribute and create new one + if(m_strNamespaceURI.isEmpty()) + { + m_domOwnerElement.setAttribute(m_strNewName, m_strValue); + m_domOwnerElement.attributes().removeNamedItem(m_strOldName); + } + else + { + m_domOwnerElement.setAttributeNS( m_strNamespaceURI, m_strNewName, m_strValue); + m_domOwnerElement.attributes().removeNamedItemNS (m_strNamespaceURI, m_strOldName); + } + + m_pDocument->updateNodeChanged(m_domOwnerElement); +} + +void KXEEditAttrNameCommand::unexecute() +{ + // it's not possible to change name. Must delete attribute and create new one + if(m_strNamespaceURI.isEmpty()) + { + m_domOwnerElement.setAttribute(m_strOldName, m_strValue); + m_domOwnerElement.attributes().removeNamedItem(m_strNewName); + + } + else + { + m_domOwnerElement.setAttributeNS( m_strNamespaceURI, m_strOldName, m_strValue); + m_domOwnerElement.attributes().removeNamedItemNS (m_strNamespaceURI, m_strNewName); + } + + m_pDocument->updateNodeChanged(m_domOwnerElement); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Editing element and its subtree as raw XML ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEEditRawXmlCommand::KXEEditRawXmlCommand( + KXEDocument *pDocument, + QDomElement &domOldElement, + QDomElement &domNewElement + ) + : KXECommand(pDocument) +{ + m_domOldElement = domOldElement; + m_domNewElement = domNewElement; + m_domParentNode = domOldElement.parentNode(); + m_afterNode = domOldElement.previousSibling(); + + if ( m_domParentNode.isNull() ) + kdError() << "KXEEditRawXmlCommand::KXEEditRawXmlCommand selected nodes parent node is empty." << endl; + +} + +KXEEditRawXmlCommand::~KXEEditRawXmlCommand() +{ +} + +void KXEEditRawXmlCommand::execute() +{ + // first delete node + if ( m_domParentNode.removeChild( m_domOldElement ).isNull() ) + kdError() << "KXEEditRawXmlCommand::execute error removing the selected node." << endl; + else + { + m_pDocument->updateNodeDeleted(m_domOldElement); + } + + // then insert new node + if (m_afterNode.isNull()) + m_domParentNode.insertBefore(m_domNewElement, m_afterNode); + else + m_domParentNode.insertAfter( m_domNewElement, m_afterNode ); + m_pDocument->updateNodeCreated(m_domNewElement); +} + +void KXEEditRawXmlCommand::unexecute() +{ + // first delete node + if ( m_domParentNode.removeChild( m_domNewElement ).isNull() ) + kdError() << "KXEEditRawXmlCommand::unexecute error removing the selected node." << endl; + else + { + m_pDocument->updateNodeDeleted(m_domNewElement); + } + + // then insert new node + if (m_afterNode.isNull()) + m_domParentNode.insertBefore(m_domOldElement, m_afterNode); + else + m_domParentNode.insertAfter( m_domOldElement, m_afterNode ); + m_pDocument->updateNodeCreated(m_domOldElement); +} diff --git a/part/commands_edit.h b/part/commands_edit.h new file mode 100644 index 0000000..c713861 --- /dev/null +++ b/part/commands_edit.h @@ -0,0 +1,346 @@ +/*************************************************************************** + commands_edit - description + ------------------- + begin : Wed Nov 26 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : a_charytoniuk@user.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 COMMANDS_EDIT_H +#define COMMANDS_EDIT_H + +#include "kxecommand.h" + +#include <klocale.h> + +#include <qobjectlist.h> + +/** +@file +@author The KXMLEditor Team +*/ + +/** + @brief Command for removing any kind of nodes. +*/ +class KXEDeleteNodeCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEDeleteNodeCommand(KXEDocument*, QDomNode &); + /** @brief Destructor */ + ~KXEDeleteNodeCommand(); + /** @brief Performs node removal.*/ + virtual void execute(); + /** @brief Node removal rollback.*/ + virtual void unexecute(); + virtual QString name() const { return i18n("Delete node"); } + protected: + /** @short Stores infromation about parent node of the node to be deleted. */ + QDomNode m_domParentNode; + /** @short Stores infromation the node to be deleted. */ + QDomNode m_domNode; + /** @short Stores infromation about sibling node of the node to be deleted. */ + QDomNode m_afterNode; +}; +/** + @short Command for removing element attributes. +*/ +class KXEDeleteAttrCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEDeleteAttrCommand(KXEDocument*, QDomElement &, QDomAttr &); + /** @brief Destructor */ + ~KXEDeleteAttrCommand(); + /** @brief Preforms attributte removal. */ + virtual void execute(); + /** @brief Attributte removal rollback. */ + virtual void unexecute(); + virtual QString name() const { return i18n("Delete attribute"); } + protected: + /** @brief Stores attribute owner. */ + QDomElement m_domOwnerElement; + /** @brief Attribute about to be removed. */ + QDomAttr m_domAttr; +}; + +/** + @short Command for removing all element attributes. +*/ +class KXEDeleteAllAttribCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEDeleteAllAttribCommand(KXEDocument*, QDomElement &); + /** @brief Destructor */ + ~KXEDeleteAllAttribCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Delete all attributes"); } + protected: + QDomElement m_domOwnerElement; + QPtrList<QDomAttr> m_listRemovedAttributes; +}; + +/** + @short Command for cutting element to clipboard. +*/ +class KXECutCommand : public KXEDeleteNodeCommand +{ + public: + /** @brief Constructor */ + KXECutCommand(KXEDocument*, QDomNode &); + /** @brief Destructor */ + ~KXECutCommand(); + virtual QString name() const { return i18n("Cut node"); } +}; + +/** + @short Command for pasting to document from clipboard. +*/ +class KXEPasteToDocumentCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEPasteToDocumentCommand(KXEDocument*, QDomDocument *, QDomElement &); + /** @brief Destructor */ + ~KXEPasteToDocumentCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Paste node to document"); } + protected: + QDomDocument * m_pDomTargetDoc; + QDomElement m_domSourceElement; +}; + +/** + @short Command for pasting element from clipboard. +*/ +class KXEPasteToElementCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEPasteToElementCommand(KXEDocument*, QDomElement &, QDomNode &); + /** @brief Destructor */ + ~KXEPasteToElementCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Paste node to element"); } + protected: + QDomElement m_domTargetElement; + QDomNode m_domSourceNode; +}; + +class KXEPasteToProcInstrCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEPasteToProcInstrCommand(KXEDocument*, QDomProcessingInstruction &, QDomProcessingInstruction &); + /** @brief Destructor */ + ~KXEPasteToProcInstrCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Paste node to proc. instruction"); } + protected: + QDomProcessingInstruction m_domTargetProcInstr; + QString m_strNewData; + QString m_strOldData; +}; + +class KXEPasteToCharDataCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEPasteToCharDataCommand(KXEDocument*, QDomCharacterData &, QDomCharacterData &); + /** @brief Destructor */ + ~KXEPasteToCharDataCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Paste node to char. data"); } + protected: + QDomCharacterData m_domTargetCharData; + QString m_strNewData; + QString m_strOldData; +}; + +/** + @short Command for Drag & Drop. +*/ +class KXEDragDropMoveCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEDragDropMoveCommand(KXEDocument*, QDomElement &, QDomNode &); + /** @brief Destructor */ + ~KXEDragDropMoveCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Drag&&drop node"); } + protected: + QDomElement m_domTargetElement; + QDomNode m_domSourceNode; + QDomNode m_domPreviousParentNode; +}; + +/** + @short Command for moving selected node up. +*/ +class KXEUpCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEUpCommand(KXEDocument*, QDomNode &); + /** @brief Destructor */ + ~KXEUpCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Move node up"); } + protected: + QDomNode m_domParentNode; + QDomNode m_domNode; +}; + +/** + @short Command for moving selected node down. +*/ +class KXEDownCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEDownCommand(KXEDocument*, QDomNode &); + /** @brief Destructor */ + ~KXEDownCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Move node down"); } + protected: + QDomNode m_domParentNode; + QDomNode m_domNode; +}; + +class KXEEditCharDataCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEEditCharDataCommand(KXEDocument*, QDomCharacterData &, const QString); + /** @brief Destructor */ + ~KXEEditCharDataCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Editing character data"); } + protected: + QDomCharacterData m_domCharacterData; + QString m_strNewContents; + QString m_strOldContents; +}; + +/** + @short Command for editing selected processing instruction. +*/ +class KXEEditProcInstrCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEEditProcInstrCommand(KXEDocument*, QDomProcessingInstruction &, const QString); + /** @brief Destructor */ + ~KXEEditProcInstrCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Editing proc. instruction"); } + protected: + QDomProcessingInstruction m_domProcInstr; + QString m_strNewData; + QString m_strOldData; +}; + +/** + @short Command for editing selected XML element. +*/ +class KXEEditElementCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEEditElementCommand(KXEDocument*, QDomElement &, const QString, const QString); + /** @brief Destructor */ + ~KXEEditElementCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Editing element"); } + protected: + QDomElement m_domElement; + QString m_strNewPrefix; + QString m_strNewName; + QString m_strOldPrefix; + QString m_strOldName; +}; + +/** + @short Command for editing element attribute value. +*/ +class KXEEditAttrValueCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEEditAttrValueCommand(KXEDocument*, const QDomAttr &, const QString); + /** @brief Destructor */ + ~KXEEditAttrValueCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Edit attribute value"); } + protected: + QDomAttr m_domAttr; + QString m_strNewValue; + QString m_strOldValue; +}; + +/** + @short Command for editing element attribute names. +*/ +class KXEEditAttrNameCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEEditAttrNameCommand(KXEDocument*, const QDomAttr &, const QString); + /** @brief Destructor */ + ~KXEEditAttrNameCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Edit attribute name"); } + protected: + QDomElement m_domOwnerElement; + QString m_strNewName; + QString m_strOldName; + QString m_strValue; + QString m_strNamespaceURI; +}; + +/** + @short Command for editing XML element as text. +*/ +class KXEEditRawXmlCommand : public KXECommand +{ + public: + /** @brief Constructor */ + KXEEditRawXmlCommand(KXEDocument*, QDomElement &, QDomElement &); + /** @brief Destructor */ + ~KXEEditRawXmlCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Editing raw XML"); } + protected: + QDomElement m_domOldElement; + QDomNode m_domParentNode; + QDomElement m_domNewElement; + QDomNode m_afterNode; +}; + +#endif diff --git a/part/commands_file.cpp b/part/commands_file.cpp new file mode 100644 index 0000000..f30ff2d --- /dev/null +++ b/part/commands_file.cpp @@ -0,0 +1,158 @@ +/*************************************************************************** + commands_file - description + ------------------- + begin : Wed Nov 26 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : a_charytoniuk@user.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 "commands_file.h" +#include <qstring.h> +#include <kurl.h> +#include <kmessagebox.h> +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Setting Version & Encoding ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEVersionEncodingCommand::KXEVersionEncodingCommand(KXEDocument* pDocument, const QString& oldData, const QString &newData) + : KXECommand(pDocument) +{ + m_strOldData = oldData; + m_strNewData = newData; +} + +KXEVersionEncodingCommand::~KXEVersionEncodingCommand() +{ +} + +void KXEVersionEncodingCommand::execute() +{ + m_pDocument->setSpecProcInstr("xml",m_strNewData); +} + +void KXEVersionEncodingCommand::unexecute() +{ + m_pDocument->setSpecProcInstr("xml",m_strOldData); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Attaching stylesheet ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEStylesheetAttachCommand::KXEStylesheetAttachCommand(KXEDocument* pDocument,const QString& prevStylesheet,const QString& newStylesheet) + : KXECommand(pDocument) +{ + m_strNewStylesheet = newStylesheet; + m_strPrevStylesheet = prevStylesheet; +} + +KXEStylesheetAttachCommand::~KXEStylesheetAttachCommand() +{ +} + +void KXEStylesheetAttachCommand::execute() +{ + m_pDocument->detachStylesheet(); + m_pDocument->attachStylesheet(KURL(m_strNewStylesheet)); +} + +void KXEStylesheetAttachCommand::unexecute() +{ + m_pDocument->detachStylesheet(); + if(!m_strPrevStylesheet.isEmpty()) + m_pDocument->attachStylesheet(KURL(m_strPrevStylesheet)); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Detaching Stylesheet ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEStylesheetDetachCommand::KXEStylesheetDetachCommand(KXEDocument* pDocument,const QString& prevStylesheet) + : KXECommand(pDocument) +{ + m_strPrevStylesheet = prevStylesheet; +} + +KXEStylesheetDetachCommand::~KXEStylesheetDetachCommand() +{ +} + +void KXEStylesheetDetachCommand::execute() +{ + m_pDocument->detachStylesheet(); +} + +void KXEStylesheetDetachCommand::unexecute() +{ + if (!m_strPrevStylesheet.isEmpty()) + m_pDocument->attachStylesheet(KURL(m_strPrevStylesheet)); +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Attaching Schema ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXESchemaAttachCommand::KXESchemaAttachCommand(KXEDocument *pDocument,const QString& newSchema) + : KXECommand(pDocument) +{ + m_pDocument = pDocument; + m_strNewSchema = newSchema; + m_strPrevSchema = ""; +} +KXESchemaAttachCommand::KXESchemaAttachCommand(KXEDocument *pDocument,const QString& newSchema,const QString& prevSchema) + : KXECommand(pDocument) +{ + m_strNewSchema = newSchema; + m_strPrevSchema = prevSchema; +} + +KXESchemaAttachCommand::~KXESchemaAttachCommand() +{ +} + +void KXESchemaAttachCommand::execute() +{ + m_pDocument->detachSchema(); // old schema is removed + m_pDocument->attachSchema(KURL(m_strNewSchema)); // new schema is applited +} + +void KXESchemaAttachCommand::unexecute() +{ + m_pDocument->detachSchema(); // new schema is removed + if (!m_strPrevSchema.isEmpty()) + m_pDocument->attachSchema(KURL(m_strPrevSchema)); // old schema is applied +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Detaching schema ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXESchemaDetachCommand::KXESchemaDetachCommand(KXEDocument* pDocument, const QString& schema) + : KXECommand(pDocument) +{ + m_schema = schema; +} + +KXESchemaDetachCommand::~KXESchemaDetachCommand() +{ +} + +void KXESchemaDetachCommand::execute() +{ + m_pDocument->detachSchema(); +} + +void KXESchemaDetachCommand::unexecute() +{ + if (!m_schema.isEmpty()) + m_pDocument->attachSchema(KURL(m_schema)); +} + diff --git a/part/commands_file.h b/part/commands_file.h new file mode 100644 index 0000000..00dc484 --- /dev/null +++ b/part/commands_file.h @@ -0,0 +1,102 @@ +/*************************************************************************** + commands_file - description + ------------------- + begin : Wed Nov 26 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : a_charytoniuk@user.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 COMMANDS_FILE_H +#define COMMANDS_FILE_H + +#include "kxecommand.h" +#include <klocale.h> + +/** @file + This file contains all commands taken from menu File which + can effect our edited document. These commans allows to have + undo/redo functionality. +*/ + +/** +Command for setting version and encoding to XML file. + +@author The KXMLEditor Team +*/ + +class KXEDocument; +class QString; + +class KXEVersionEncodingCommand : public KXECommand +{ + public: + KXEVersionEncodingCommand(KXEDocument* pDocument, const QString& oldData, const QString &newData); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Changing version and encoding"); } + ~KXEVersionEncodingCommand(); + protected: + QString m_strOldData; + QString m_strNewData; +}; + +class KXEStylesheetAttachCommand : public KXECommand +{ + public: + KXEStylesheetAttachCommand(KXEDocument* pDocument,const QString& prevStylesheet,const QString& newStylesheet); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Attaching stylesheet ")+m_strNewStylesheet; } + ~KXEStylesheetAttachCommand(); + protected: + QString m_strPrevStylesheet; + QString m_strNewStylesheet; +}; + +class KXEStylesheetDetachCommand : public KXECommand +{ + public: + KXEStylesheetDetachCommand(KXEDocument* pDocument,const QString& prevStylesheet); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Detaching stylesheet ")+m_strPrevStylesheet; } + ~KXEStylesheetDetachCommand(); + protected: + QString m_strPrevStylesheet; +}; + +class KXESchemaAttachCommand : public KXECommand +{ + public: + KXESchemaAttachCommand(KXEDocument *pDocument,const QString& newSchema); + KXESchemaAttachCommand(KXEDocument *pDocument,const QString& newSchema, const QString& prevSchema); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Attaching schema ")+m_strNewSchema; } + ~KXESchemaAttachCommand(); + protected: + QString m_strNewSchema; + QString m_strPrevSchema; +}; + +class KXESchemaDetachCommand : public KXECommand +{ + public: + KXESchemaDetachCommand(KXEDocument* pDocument, const QString& schema); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Detaching schema ")+m_schema; } + ~KXESchemaDetachCommand(); + protected: + QString m_schema; +}; + +#endif diff --git a/part/commands_insert.cpp b/part/commands_insert.cpp new file mode 100644 index 0000000..9f17d51 --- /dev/null +++ b/part/commands_insert.cpp @@ -0,0 +1,329 @@ +/*************************************************************************** + commands_insert - description + ------------------- + begin : Wed Nov 26 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : lvanek@user.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 "commands_insert.h" + +#include <qstring.h> + +#include <kdebug.h> + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Inserting new XML element ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEElementCommand::KXEElementCommand( + KXEDocument *pDocument, + QDomDocument * pDomDoc, + QString strNsURI, + QString strPrefix, + QString strName + ) + : KXECommand(pDocument) +{ + if ( pDomDoc == 0 ) + kdError() << "KXEElementCommand::KXEElementCommand the given XML document object is empty." << endl; + + m_pDomDoc = pDomDoc; + + if ( strNsURI.isEmpty() ) + m_domElement = m_pDomDoc->createElement( strName ); + else + m_domElement = m_pDomDoc->createElementNS( strNsURI, strPrefix + ":" + strName ); +} + +KXEElementCommand::KXEElementCommand( + KXEDocument *pDocument, + QDomElement & domParentElement, + QString strNsURI, + QString strPrefix, + QString strName, + bool bAtTop + ) + : KXECommand(pDocument) +{ + if ( domParentElement.isNull() ) + kdError() << "KXEElementCommand::KXEElementCommand the given XML element object is empty." << endl; + + m_domParentElement = domParentElement; + m_pDomDoc = 0; + m_bAtTop = bAtTop; + + if ( strNsURI.isEmpty() ) + m_domElement = m_domParentElement.ownerDocument().createElement( strName ); + else + m_domElement = m_domParentElement.ownerDocument().createElementNS( strNsURI, strPrefix + ":" + strName ); +} + +KXEElementCommand::~KXEElementCommand() +{ +} + +void KXEElementCommand::execute() +{ + if ( m_pDomDoc ) + { + // Insert root element + m_pDomDoc->appendChild( m_domElement ); + } + else + { + if( !m_domParentElement.isNull() ) + { + // Insert child element + if ( m_bAtTop ) + { // insert as first child + QDomNode domFirstChildNode = m_domParentElement.firstChild(); + if ( domFirstChildNode.isNull() ) + m_domParentElement.appendChild( m_domElement ); // no childs yet -> simply append + else + m_domParentElement.insertBefore( m_domElement, domFirstChildNode ); + } + else // insert as last child + m_domParentElement.appendChild( m_domElement ); + } + else + { + kdError() << "KXEElementCommand::execute document and element object is empty." << endl; + } + } + m_pDocument->updateNodeCreated(m_domElement); +} + +void KXEElementCommand::unexecute() +{ + if ( m_domElement.parentNode().removeChild( m_domElement ).isNull() ) + kdError() << "KXEElementCommand::unexecute error removing the selected node." << endl; + else + { + m_pDocument->updateNodeDeleted(m_domElement); + } +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// inserting new attribute ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEAttributeCommand::KXEAttributeCommand( + KXEDocument *pDocument, + QDomElement &domOwnerElement, + QString strNamespace, + QString strQName, + QString strValue + ) + : KXECommand(pDocument) +{ + if ( domOwnerElement.isNull() ) + { + kdError() << k_funcinfo << "KXEAttributeCommand::KXEAttributeCommand - The given owner element is empty." << endl; + return; + } + + m_domOwnerElement = domOwnerElement; + m_strNamespace = strNamespace; + m_strQName = strQName; + m_strValue = strValue; +} + +KXEAttributeCommand::~KXEAttributeCommand() +{ +} + +void KXEAttributeCommand::execute() +{ + if ( m_strNamespace.isEmpty() ) + m_domOwnerElement.setAttribute( m_strQName, m_strValue ); + else + m_domOwnerElement.setAttributeNS( m_strNamespace, m_strQName, m_strValue ); + + m_pDocument->updateNodeChanged( m_domOwnerElement ) ; +} + +void KXEAttributeCommand::unexecute() +{ + if ( m_strNamespace.isEmpty() ) + m_domOwnerElement.removeAttribute(m_strQName); + else + m_domOwnerElement.removeAttributeNS(m_strNamespace, m_strQName); + + m_pDocument->updateNodeChanged( m_domOwnerElement ) ; +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Inserting new character data ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXECharDataCommand::KXECharDataCommand( + KXEDocument *pDocument, + QDomElement & domParentElement, + bool bAtTop, + CharDataKind eCharDataKind, + QString strContents + ) + : KXECommand(pDocument) +{ + if ( domParentElement.isNull() ) + { + kdError() << k_funcinfo << "KXECharDataCommand::KXECharDataCommand - The given parent object is empty." << endl; + return; + } + + m_domParentElement = domParentElement; + m_bAtTop = bAtTop; + + switch ( eCharDataKind ) + { + case CharDataTextNode: + m_domCharData = domParentElement.ownerDocument().createTextNode( strContents ); + break; + + case CharDataCDATASection: + m_domCharData = domParentElement.ownerDocument().createCDATASection( strContents ); + break; + + case CharDataComment: + m_domCharData = domParentElement.ownerDocument().createComment( strContents ); + break; + + default: + kdError() << "KXECharDataCommand::KXECharDataCommand unrecognized char. data type." << endl; + break; + } +} + +KXECharDataCommand::~KXECharDataCommand() +{ +} + +void KXECharDataCommand::execute() +{ + if ( m_bAtTop ) + { // insert as first child + QDomNode domFirstChildNode = m_domParentElement.firstChild(); + if ( domFirstChildNode.isNull() ) + m_domParentElement.appendChild( m_domCharData ); // no childs yet -> simply append + else + m_domParentElement.insertBefore( m_domCharData, domFirstChildNode ); + } + else // insert as last child + m_domParentElement.appendChild( m_domCharData ); + + m_pDocument->updateNodeCreated(m_domCharData); +} + +void KXECharDataCommand::unexecute() +{ + if ( m_domCharData.parentNode().removeChild( m_domCharData ).isNull() ) + kdError() << "KXECharDataCommand::unexecute error removing the selected node." << endl; + else + { + m_pDocument->updateNodeDeleted(m_domCharData); + } +} + +////////////////////////////////////////////////////////////////////////////////////////// +/////////// Inserting new proc instr. ////////// +////////////////////////////////////////////////////////////////////////////////////////// + +KXEProcInstrCommand::KXEProcInstrCommand( + KXEDocument *pDocument, + QDomDocument * pDomDoc, + bool bAtTop, + QString strTarget, + QString strData + ) + : KXECommand(pDocument) +{ + if ( pDomDoc == 0 ) + { + kdError() << k_funcinfo << "KXEProcInstrCommand::KXEProcInstrCommand - The given parent object is empty." << endl; + return; + } + + m_pDomDoc = pDomDoc; + m_bAtTop = bAtTop; + + m_domProcInstr = pDomDoc->createProcessingInstruction( strTarget, strData ); +} + +KXEProcInstrCommand::KXEProcInstrCommand( + KXEDocument *pDocument, + QDomElement & domParentElement, + bool bAtTop, + QString strTarget, + QString strData + ) + : KXECommand(pDocument) +{ + if ( domParentElement.isNull() ) + { + kdError() << k_funcinfo << "KXEProcInstrCommand::KXEProcInstrCommand - The given parent object is empty." << endl; + return; + } + + m_domParentElement = domParentElement; + m_pDomDoc = 0; + m_bAtTop = bAtTop; + + m_domProcInstr = domParentElement.ownerDocument().createProcessingInstruction( strTarget, strData ); +} + + +KXEProcInstrCommand::~KXEProcInstrCommand() +{ +} + +void KXEProcInstrCommand::execute() +{ + if ( m_pDomDoc ) + { + // Insert root proc. instr + m_pDomDoc->appendChild( m_domProcInstr ); + } + else + { + if( !m_domParentElement.isNull() ) + { + // Insert child proc. instr + if ( m_bAtTop ) + { // insert as first child + QDomNode domFirstChildNode = m_domParentElement.firstChild(); + if ( domFirstChildNode.isNull() ) + m_domParentElement.appendChild( m_domProcInstr ); // no childs yet -> simply append + else + m_domParentElement.insertBefore( m_domProcInstr, domFirstChildNode ); + } + else // insert as last child + m_domParentElement.appendChild( m_domProcInstr ); + } + else + { + kdError() << "KXEElementCommand::execute document and element object is empty." << endl; + } + } + m_pDocument->updateNodeCreated(m_domProcInstr); +} + +void KXEProcInstrCommand::unexecute() +{ + if ( m_domProcInstr.parentNode().removeChild( m_domProcInstr ).isNull() ) + kdError() << "KXEProcInstrCommand::unexecute error removing the selected node." << endl; + else + { + m_pDocument->updateNodeDeleted(m_domProcInstr); + } +} + + diff --git a/part/commands_insert.h b/part/commands_insert.h new file mode 100644 index 0000000..4d9da8d --- /dev/null +++ b/part/commands_insert.h @@ -0,0 +1,94 @@ +/*************************************************************************** + commands_insert - description + ------------------- + begin : Wed Nov 26 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : lvanek.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 COMMANDS_INSERT_H +#define COMMANDS_INSERT_H + +#include <klocale.h> + +#include "kxecommand.h" +#include "kxechardatadialog.h" + +/** +@author The KXMLEditor Team +*/ +class KXEElementCommand : public KXECommand +{ + public: + KXEElementCommand(KXEDocument*, QDomDocument *, QString, QString, QString); + KXEElementCommand(KXEDocument*, QDomElement &, QString, QString, QString, bool); + ~KXEElementCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Insert element"); } + + protected: + QDomDocument * m_pDomDoc; + QDomElement m_domParentElement; + bool m_bAtTop; + QDomElement m_domElement; +}; + +class KXEAttributeCommand : public KXECommand +{ + public: + KXEAttributeCommand(KXEDocument*, QDomElement &, QString, QString, QString); + ~KXEAttributeCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Insert attribute"); } + + protected: + QString m_strNamespace; + QString m_strQName; + QString m_strValue; + QDomElement m_domOwnerElement; +}; + +class KXECharDataCommand : public KXECommand +{ + public: + KXECharDataCommand(KXEDocument*, QDomElement &, bool, CharDataKind, QString); + ~KXECharDataCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Insert char data"); } + + protected: + + bool m_bAtTop; + QDomElement m_domParentElement; + QDomCharacterData m_domCharData; +}; + +class KXEProcInstrCommand : public KXECommand +{ + public: + KXEProcInstrCommand(KXEDocument*, QDomDocument *, bool, QString, QString); + KXEProcInstrCommand(KXEDocument*, QDomElement &, bool, QString, QString); + ~KXEProcInstrCommand(); + virtual void execute(); + virtual void unexecute(); + virtual QString name() const { return i18n("Insert proc. instr."); } + + protected: + QDomDocument * m_pDomDoc; + QDomElement m_domParentElement; + bool m_bAtTop; + QDomProcessingInstruction m_domProcInstr; +}; + +#endif diff --git a/part/dcopiface_part_ro.cpp b/part/dcopiface_part_ro.cpp new file mode 100644 index 0000000..c2794d0 --- /dev/null +++ b/part/dcopiface_part_ro.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + dcopiface_part_ro.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_part_ro.h" +#include "kxmleditorpart.h" +//--------------------------------------------------------------------------- +// KXMLEditorPartIfaceReadOnly +//--------------------------------------------------------------------------- +QString +KXMLEditorPartIfaceReadOnly::saveAsFile(const QString & ) +{ + return "Not implemented."; +} + +QString +KXMLEditorPartIfaceReadOnly::selectNode(const QString & szPathToNode) +{ + m_pKXEPart->slotPathSelected(szPathToNode); + + if ( m_pKXEPart->getSelectedPath() == szPathToNode ) + return "Selecting node failed."; + + return QString(); +} + +QString +KXMLEditorPartIfaceReadOnly::currentNode() const +{ + return m_pKXEPart->getSelectedPath(); +} + + +//--------------------------------------------------------------------------- +// KXMLEditorPartIface +//--------------------------------------------------------------------------- +QString +KXMLEditorPartIfaceReadWrite::openURL(const QString & szURL) +{ + KURL url(szURL); + if (! url.isValid () ) + return "URL is not valid."; + if ( m_pKXEPart->openURL(url) ) + return QString(); + else + return "Opening URL failed."; +} + + +QString +KXMLEditorPartIfaceReadWrite::close() +{ + return "Not implemented."; +} + diff --git a/part/dcopiface_part_ro.h b/part/dcopiface_part_ro.h new file mode 100644 index 0000000..90f5982 --- /dev/null +++ b/part/dcopiface_part_ro.h @@ -0,0 +1,124 @@ +/*************************************************************************** + dcopiface_part_ro.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_PART_RO_H +#define DCOPIFACE_PART_RO_H + +#include <dcopobject.h> + + +class KXMLEditorPart; + /** + * Allows perform action on represetntaion of XML file via DCOP protocol. + * behavies as interface to @ref KXMLEditorPart and to it adresses most of requestests received by DCOP + * + *@see KXMLEditorPart + * + *@short Read only DCOP interface for XML document Kpart based kxmleditor. + * + *@author The KXMLEditor Team (matkor@users.sourceforge.net) + **/ + +class KXMLEditorPartIfaceReadOnly + :virtual public DCOPObject +{ + K_DCOP + +protected: + /** @ref KXMLEditorPart which Iface represensts **/ + KXMLEditorPart * m_pKXEPart; + +public: + /** + * Default constructor + * + * @param kxe_part Specifies on what @ref KXMLEditorPart will interface operate. + **/ + KXMLEditorPartIfaceReadOnly(KXMLEditorPart * kxe_part,const char * dcop_name = "KXMLEditorPartIface") + : DCOPObject(dcop_name) + { + m_pKXEPart = kxe_part; + } + virtual ~KXMLEditorPartIfaceReadOnly() + {}; +k_dcop: + /** + * Saves document as file + * + * @returns Error description or empty string if file succesfully saved. + **/ + + QString saveAsFile(const QString & path_to_file); + + /** Tries to change current node + * @param pathToNode Path to new node + * @returns Empty string if selection OK otherwise error description + **/ + QString selectNode(const QString & pathToNode); + + /** Returns path to current node + * @returns If error empty string + **/ + QString currentNode() const; + +}; + + + + /** + *@short Read/Write DCOP inteface for Kpart based kxmleditor. + *@author The KXMLEditor Team + **/ +// +class KXMLEditorPartIfaceReadWrite + :public KXMLEditorPartIfaceReadOnly +{ + K_DCOP + /** + * Default constructor + * + * @param kxe_part Specifies on what @ref KXMLEditorPart will interface operate. + **/ +public: + KXMLEditorPartIfaceReadWrite(KXMLEditorPart * kxe_part,const char * dcop_name = "KXMLEditorPartIface") + : DCOPObject(dcop_name) + ,KXMLEditorPartIfaceReadOnly(kxe_part,dcop_name) + {} + virtual ~KXMLEditorPartIfaceReadWrite() + {}; +k_dcop: + + /** + * Opens given file + * + * @returns Error description or empty string if file succesfully loaded. + **/ + QString openURL(const QString & szURL); + + /** + * Closes object behind interface. + * In curent implementation it means closing entire KXMLEditor. + * + * @returns Error description or empty string if program closed. + **/ + QString close(); + + +}; + + +#endif // DCOPIFACE_PART_RO_H diff --git a/part/icons/Makefile.am b/part/icons/Makefile.am new file mode 100644 index 0000000..41028ae --- /dev/null +++ b/part/icons/Makefile.am @@ -0,0 +1,155 @@ + +EXTRA_DIST = hi16-action-bookmark_next.png hi16-action-xml_cdata.png hi16-action-xml_comment.png hi16-action-xml_text.png hi16-action-bookmark_prev.png hi16-action-collapse_node.png hi16-action-expand_node.png hi16-action-xml_delete_attribute.png hi16-action-xml_delete_contents.png hi16-action-xml_delete_element.png hi16-action-xml_delete_procins.png hi16-action-xml_edit_attribute.png hi16-action-xml_edit_contents.png hi16-action-xml_edit_element.png hi16-action-xml_edit_procins.png hi16-action-xml_insert_attribute.png hi16-action-xml_insert_contents.png hi16-action-xml_insert_element.png hi16-action-xml_insert_procins.png hi16-action-xml_move_item_down.png hi16-action-xml_move_item_up.png hi22-action-bookmark_next.png hi22-action-bookmark_prev.png hi22-action-collapse_node.png hi22-action-expand_node.png hi22-action-xml_delete_attribute.png hi22-action-xml_delete_contents.png hi22-action-xml_delete_element.png hi22-action-xml_delete_procins.png hi22-action-xml_edit_attribute.png hi22-action-xml_edit_contents.png hi22-action-xml_edit_element.png hi22-action-xml_edit_procins.png hi22-action-xml_insert_attribute.png hi22-action-xml_insert_contents.png hi22-action-xml_insert_element.png hi22-action-xml_insert_procins.png hi22-action-xml_move_item_down.png hi22-action-xml_move_item_up.png hi32-action-bookmark_next.png hi32-action-bookmark_prev.png hi32-action-xml_move_item_down.png hi32-action-xml_move_item_up.png lo16-action-bookmark_next.png lo16-action-bookmark_prev.png lo16-action-collapse_node.png lo16-action-expand_node.png lo16-action-xml_delete_attribute.png lo16-action-xml_delete_contents.png lo16-action-xml_delete_element.png lo16-action-xml_delete_procins.png lo16-action-xml_edit_attribute.png lo16-action-xml_edit_contents.png lo16-action-xml_edit_element.png lo16-action-xml_edit_procins.png lo16-action-xml_insert_attribute.png lo16-action-xml_insert_contents.png lo16-action-xml_insert_element.png lo16-action-xml_insert_procins.png lo16-action-xml_move_item_down.png lo16-action-xml_move_item_up.png \ + lo32-app-kxmleditor.png lo16-app-kxmleditor.png \ + hi32-app-kxmleditor.png hi48-app-kxmleditor.png + +install-data-local: + $(mkinstalldirs) $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/ + $(INSTALL_DATA) $(srcdir)/hi16-action-bookmark_next.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/bookmark_next.png + $(INSTALL_DATA) $(srcdir)/hi16-action-bookmark_prev.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/bookmark_prev.png + $(INSTALL_DATA) $(srcdir)/hi16-action-collapse_node.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/collapse_node.png + $(INSTALL_DATA) $(srcdir)/hi16-action-expand_node.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/expand_node.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_delete_attribute.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_delete_attribute.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_delete_contents.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_delete_contents.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_delete_element.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_delete_element.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_delete_procins.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_delete_procins.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_edit_attribute.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_edit_attribute.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_edit_contents.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_edit_contents.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_edit_element.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_edit_element.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_edit_procins.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_edit_procins.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_insert_attribute.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_insert_attribute.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_insert_contents.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_insert_contents.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_insert_element.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_insert_element.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_insert_procins.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_insert_procins.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_move_item_down.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_move_item_down.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_move_item_up.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_move_item_up.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_text.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_text.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_cdata.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_cdata.png + $(INSTALL_DATA) $(srcdir)/hi16-action-xml_comment.png $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_comment.png + $(mkinstalldirs) $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/ + $(INSTALL_DATA) $(srcdir)/hi22-action-bookmark_next.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/bookmark_next.png + $(INSTALL_DATA) $(srcdir)/hi22-action-bookmark_prev.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/bookmark_prev.png + $(INSTALL_DATA) $(srcdir)/hi22-action-collapse_node.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/collapse_node.png + $(INSTALL_DATA) $(srcdir)/hi22-action-expand_node.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/expand_node.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_delete_attribute.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_delete_attribute.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_delete_contents.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_delete_contents.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_delete_element.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_delete_element.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_delete_procins.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_delete_procins.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_edit_attribute.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_edit_attribute.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_edit_contents.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_edit_contents.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_edit_element.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_edit_element.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_edit_procins.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_edit_procins.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_insert_attribute.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_insert_attribute.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_insert_contents.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_insert_contents.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_insert_element.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_insert_element.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_insert_procins.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_insert_procins.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_move_item_down.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_move_item_down.png + $(INSTALL_DATA) $(srcdir)/hi22-action-xml_move_item_up.png $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_move_item_up.png + $(mkinstalldirs) $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/ + $(INSTALL_DATA) $(srcdir)/hi32-action-bookmark_next.png $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/bookmark_next.png + $(INSTALL_DATA) $(srcdir)/hi32-action-bookmark_prev.png $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/bookmark_prev.png + $(INSTALL_DATA) $(srcdir)/hi32-action-xml_move_item_down.png $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/xml_move_item_down.png + $(INSTALL_DATA) $(srcdir)/hi32-action-xml_move_item_up.png $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/xml_move_item_up.png + $(mkinstalldirs) $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/ + $(INSTALL_DATA) $(srcdir)/lo16-action-bookmark_next.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/bookmark_next.png + $(INSTALL_DATA) $(srcdir)/lo16-action-bookmark_prev.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/bookmark_prev.png + $(INSTALL_DATA) $(srcdir)/lo16-action-collapse_node.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/collapse_node.png + $(INSTALL_DATA) $(srcdir)/lo16-action-expand_node.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/expand_node.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_delete_attribute.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_delete_attribute.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_delete_contents.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_delete_contents.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_delete_element.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_delete_element.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_delete_procins.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_delete_procins.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_edit_attribute.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_edit_attribute.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_edit_contents.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_edit_contents.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_edit_element.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_edit_element.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_edit_procins.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_edit_procins.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_insert_attribute.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_insert_attribute.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_insert_contents.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_insert_contents.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_insert_element.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_insert_element.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_insert_procins.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_insert_procins.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_move_item_down.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_move_item_down.png + $(INSTALL_DATA) $(srcdir)/lo16-action-xml_move_item_up.png $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_move_item_up.png + $(mkinstalldirs) $(kde_icondir)/locolor/32x32/apps/ + $(INSTALL_DATA) $(srcdir)/lo32-app-kxmleditor.png $(kde_icondir)/locolor/32x32/apps/kxmleditor.png + $(mkinstalldirs) $(kde_icondir)/locolor/16x16/apps/ + $(INSTALL_DATA) $(srcdir)/lo16-app-kxmleditor.png $(kde_icondir)/locolor/16x16/apps/kxmleditor.png + $(mkinstalldirs) $(kde_icondir)/hicolor/32x32/apps/ + $(INSTALL_DATA) $(srcdir)/hi32-app-kxmleditor.png $(kde_icondir)/hicolor/32x32/apps/kxmleditor.png + $(mkinstalldirs) $(kde_icondir)/hicolor/48x48/apps/ + $(INSTALL_DATA) $(srcdir)/hi48-app-kxmleditor.png $(kde_icondir)/hicolor/48x48/apps/kxmleditor.png + + +uninstall-local: + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/bookmark_next.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/bookmark_prev.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/collapse_node.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/expand_node.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_delete_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_delete_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_delete_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_delete_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_edit_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_edit_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_edit_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_edit_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_insert_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_insert_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_insert_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_insert_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_move_item_down.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/xml_move_item_up.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/bookmark_next.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/bookmark_prev.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/collapse_node.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/expand_node.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_delete_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_delete_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_delete_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_delete_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_edit_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_edit_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_edit_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_edit_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_insert_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_insert_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_insert_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_insert_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_move_item_down.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/xml_move_item_up.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/bookmark_next.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/bookmark_prev.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/xml_move_item_down.png + -rm -f $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/xml_move_item_up.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_text.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_cdata.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_comment.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/bookmark_next.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/bookmark_prev.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/collapse_node.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/expand_node.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_delete_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_delete_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_delete_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_delete_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_edit_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_edit_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_edit_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_edit_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_insert_attribute.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_insert_contents.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_insert_element.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_insert_procins.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_move_item_down.png + -rm -f $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/xml_move_item_up.png + -rmdir $(kde_datadir)/kxmleditor/icons/hicolor/16x16/actions/ + -rmdir $(kde_datadir)/kxmleditor/icons/hicolor/22x22/actions/ + -rmdir $(kde_datadir)/kxmleditor/icons/hicolor/32x32/actions/ + -rmdir $(kde_datadir)/kxmleditor/icons/locolor/16x16/actions/ + -rm -f $(kde_icondir)/locolor/32x32/apps/kxmleditor.png + -rmdir $(kde_icondir)/locolor/32x32/apps/ + -rm -f $(kde_icondir)/locolor/16x16/apps/kxmleditor.png + -rmdir $(kde_icondir)/locolor/16x16/apps/ + -rm -f $(kde_icondir)/hicolor/32x32/apps/kxmleditor.png + -rmdir $(kde_icondir)/hicolor/32x32/apps/ + -rm -f $(kde_icondir)/hicolor/48x48/apps/kxmleditor.png + -rmdir $(kde_icondir)/hicolor/48x48/apps/ diff --git a/part/icons/hi16-action-bookmark_next.png b/part/icons/hi16-action-bookmark_next.png Binary files differnew file mode 100644 index 0000000..12b6893 --- /dev/null +++ b/part/icons/hi16-action-bookmark_next.png diff --git a/part/icons/hi16-action-bookmark_prev.png b/part/icons/hi16-action-bookmark_prev.png Binary files differnew file mode 100644 index 0000000..32cbc7a --- /dev/null +++ b/part/icons/hi16-action-bookmark_prev.png diff --git a/part/icons/hi16-action-collapse_node.png b/part/icons/hi16-action-collapse_node.png Binary files differnew file mode 100644 index 0000000..9efc36a --- /dev/null +++ b/part/icons/hi16-action-collapse_node.png diff --git a/part/icons/hi16-action-expand_node.png b/part/icons/hi16-action-expand_node.png Binary files differnew file mode 100644 index 0000000..f8354df --- /dev/null +++ b/part/icons/hi16-action-expand_node.png diff --git a/part/icons/hi16-action-xml_cdata.png b/part/icons/hi16-action-xml_cdata.png Binary files differnew file mode 100644 index 0000000..ba70ca1 --- /dev/null +++ b/part/icons/hi16-action-xml_cdata.png diff --git a/part/icons/hi16-action-xml_comment.png b/part/icons/hi16-action-xml_comment.png Binary files differnew file mode 100644 index 0000000..1acd578 --- /dev/null +++ b/part/icons/hi16-action-xml_comment.png diff --git a/part/icons/hi16-action-xml_delete_attribute.png b/part/icons/hi16-action-xml_delete_attribute.png Binary files differnew file mode 100644 index 0000000..671da71 --- /dev/null +++ b/part/icons/hi16-action-xml_delete_attribute.png diff --git a/part/icons/hi16-action-xml_delete_contents.png b/part/icons/hi16-action-xml_delete_contents.png Binary files differnew file mode 100644 index 0000000..00f1416 --- /dev/null +++ b/part/icons/hi16-action-xml_delete_contents.png diff --git a/part/icons/hi16-action-xml_delete_element.png b/part/icons/hi16-action-xml_delete_element.png Binary files differnew file mode 100644 index 0000000..4122060 --- /dev/null +++ b/part/icons/hi16-action-xml_delete_element.png diff --git a/part/icons/hi16-action-xml_delete_procins.png b/part/icons/hi16-action-xml_delete_procins.png Binary files differnew file mode 100644 index 0000000..184cba6 --- /dev/null +++ b/part/icons/hi16-action-xml_delete_procins.png diff --git a/part/icons/hi16-action-xml_edit_attribute.png b/part/icons/hi16-action-xml_edit_attribute.png Binary files differnew file mode 100644 index 0000000..10e5940 --- /dev/null +++ b/part/icons/hi16-action-xml_edit_attribute.png diff --git a/part/icons/hi16-action-xml_edit_contents.png b/part/icons/hi16-action-xml_edit_contents.png Binary files differnew file mode 100644 index 0000000..e67bcf4 --- /dev/null +++ b/part/icons/hi16-action-xml_edit_contents.png diff --git a/part/icons/hi16-action-xml_edit_element.png b/part/icons/hi16-action-xml_edit_element.png Binary files differnew file mode 100644 index 0000000..256a24e --- /dev/null +++ b/part/icons/hi16-action-xml_edit_element.png diff --git a/part/icons/hi16-action-xml_edit_procins.png b/part/icons/hi16-action-xml_edit_procins.png Binary files differnew file mode 100644 index 0000000..1773cda --- /dev/null +++ b/part/icons/hi16-action-xml_edit_procins.png diff --git a/part/icons/hi16-action-xml_insert_attribute.png b/part/icons/hi16-action-xml_insert_attribute.png Binary files differnew file mode 100644 index 0000000..b02f1e0 --- /dev/null +++ b/part/icons/hi16-action-xml_insert_attribute.png diff --git a/part/icons/hi16-action-xml_insert_contents.png b/part/icons/hi16-action-xml_insert_contents.png Binary files differnew file mode 100644 index 0000000..c5cda99 --- /dev/null +++ b/part/icons/hi16-action-xml_insert_contents.png diff --git a/part/icons/hi16-action-xml_insert_element.png b/part/icons/hi16-action-xml_insert_element.png Binary files differnew file mode 100644 index 0000000..fcc234f --- /dev/null +++ b/part/icons/hi16-action-xml_insert_element.png diff --git a/part/icons/hi16-action-xml_insert_procins.png b/part/icons/hi16-action-xml_insert_procins.png Binary files differnew file mode 100644 index 0000000..824ee57 --- /dev/null +++ b/part/icons/hi16-action-xml_insert_procins.png diff --git a/part/icons/hi16-action-xml_move_item_down.png b/part/icons/hi16-action-xml_move_item_down.png Binary files differnew file mode 100644 index 0000000..30e0602 --- /dev/null +++ b/part/icons/hi16-action-xml_move_item_down.png diff --git a/part/icons/hi16-action-xml_move_item_up.png b/part/icons/hi16-action-xml_move_item_up.png Binary files differnew file mode 100644 index 0000000..7bb1b68 --- /dev/null +++ b/part/icons/hi16-action-xml_move_item_up.png diff --git a/part/icons/hi16-action-xml_text.png b/part/icons/hi16-action-xml_text.png Binary files differnew file mode 100644 index 0000000..fb485a3 --- /dev/null +++ b/part/icons/hi16-action-xml_text.png diff --git a/part/icons/hi22-action-bookmark_next.png b/part/icons/hi22-action-bookmark_next.png Binary files differnew file mode 100644 index 0000000..d685663 --- /dev/null +++ b/part/icons/hi22-action-bookmark_next.png diff --git a/part/icons/hi22-action-bookmark_prev.png b/part/icons/hi22-action-bookmark_prev.png Binary files differnew file mode 100644 index 0000000..33ecf83 --- /dev/null +++ b/part/icons/hi22-action-bookmark_prev.png diff --git a/part/icons/hi22-action-collapse_node.png b/part/icons/hi22-action-collapse_node.png Binary files differnew file mode 100644 index 0000000..234711f --- /dev/null +++ b/part/icons/hi22-action-collapse_node.png diff --git a/part/icons/hi22-action-expand_node.png b/part/icons/hi22-action-expand_node.png Binary files differnew file mode 100644 index 0000000..5738150 --- /dev/null +++ b/part/icons/hi22-action-expand_node.png diff --git a/part/icons/hi22-action-xml_delete_attribute.png b/part/icons/hi22-action-xml_delete_attribute.png Binary files differnew file mode 100644 index 0000000..caef038 --- /dev/null +++ b/part/icons/hi22-action-xml_delete_attribute.png diff --git a/part/icons/hi22-action-xml_delete_contents.png b/part/icons/hi22-action-xml_delete_contents.png Binary files differnew file mode 100644 index 0000000..3fe3eb6 --- /dev/null +++ b/part/icons/hi22-action-xml_delete_contents.png diff --git a/part/icons/hi22-action-xml_delete_element.png b/part/icons/hi22-action-xml_delete_element.png Binary files differnew file mode 100644 index 0000000..c161c78 --- /dev/null +++ b/part/icons/hi22-action-xml_delete_element.png diff --git a/part/icons/hi22-action-xml_delete_procins.png b/part/icons/hi22-action-xml_delete_procins.png Binary files differnew file mode 100644 index 0000000..df8f911 --- /dev/null +++ b/part/icons/hi22-action-xml_delete_procins.png diff --git a/part/icons/hi22-action-xml_edit_attribute.png b/part/icons/hi22-action-xml_edit_attribute.png Binary files differnew file mode 100644 index 0000000..83da5de --- /dev/null +++ b/part/icons/hi22-action-xml_edit_attribute.png diff --git a/part/icons/hi22-action-xml_edit_contents.png b/part/icons/hi22-action-xml_edit_contents.png Binary files differnew file mode 100644 index 0000000..0cae376 --- /dev/null +++ b/part/icons/hi22-action-xml_edit_contents.png diff --git a/part/icons/hi22-action-xml_edit_element.png b/part/icons/hi22-action-xml_edit_element.png Binary files differnew file mode 100644 index 0000000..ffa4149 --- /dev/null +++ b/part/icons/hi22-action-xml_edit_element.png diff --git a/part/icons/hi22-action-xml_edit_procins.png b/part/icons/hi22-action-xml_edit_procins.png Binary files differnew file mode 100644 index 0000000..ca5ac18 --- /dev/null +++ b/part/icons/hi22-action-xml_edit_procins.png diff --git a/part/icons/hi22-action-xml_insert_attribute.png b/part/icons/hi22-action-xml_insert_attribute.png Binary files differnew file mode 100644 index 0000000..e074c58 --- /dev/null +++ b/part/icons/hi22-action-xml_insert_attribute.png diff --git a/part/icons/hi22-action-xml_insert_contents.png b/part/icons/hi22-action-xml_insert_contents.png Binary files differnew file mode 100644 index 0000000..8b463b1 --- /dev/null +++ b/part/icons/hi22-action-xml_insert_contents.png diff --git a/part/icons/hi22-action-xml_insert_element.png b/part/icons/hi22-action-xml_insert_element.png Binary files differnew file mode 100644 index 0000000..83b71cb --- /dev/null +++ b/part/icons/hi22-action-xml_insert_element.png diff --git a/part/icons/hi22-action-xml_insert_procins.png b/part/icons/hi22-action-xml_insert_procins.png Binary files differnew file mode 100644 index 0000000..f861003 --- /dev/null +++ b/part/icons/hi22-action-xml_insert_procins.png diff --git a/part/icons/hi22-action-xml_move_item_down.png b/part/icons/hi22-action-xml_move_item_down.png Binary files differnew file mode 100644 index 0000000..f5c0c69 --- /dev/null +++ b/part/icons/hi22-action-xml_move_item_down.png diff --git a/part/icons/hi22-action-xml_move_item_up.png b/part/icons/hi22-action-xml_move_item_up.png Binary files differnew file mode 100644 index 0000000..b3784ef --- /dev/null +++ b/part/icons/hi22-action-xml_move_item_up.png diff --git a/part/icons/hi32-action-bookmark_next.png b/part/icons/hi32-action-bookmark_next.png Binary files differnew file mode 100644 index 0000000..4332ea8 --- /dev/null +++ b/part/icons/hi32-action-bookmark_next.png diff --git a/part/icons/hi32-action-bookmark_prev.png b/part/icons/hi32-action-bookmark_prev.png Binary files differnew file mode 100644 index 0000000..5e1dd5d --- /dev/null +++ b/part/icons/hi32-action-bookmark_prev.png diff --git a/part/icons/hi32-action-xml_move_item_down.png b/part/icons/hi32-action-xml_move_item_down.png Binary files differnew file mode 100644 index 0000000..e7230c1 --- /dev/null +++ b/part/icons/hi32-action-xml_move_item_down.png diff --git a/part/icons/hi32-action-xml_move_item_up.png b/part/icons/hi32-action-xml_move_item_up.png Binary files differnew file mode 100644 index 0000000..046b99b --- /dev/null +++ b/part/icons/hi32-action-xml_move_item_up.png diff --git a/part/icons/hi32-app-kxmleditor.png b/part/icons/hi32-app-kxmleditor.png Binary files differnew file mode 100644 index 0000000..763034d --- /dev/null +++ b/part/icons/hi32-app-kxmleditor.png diff --git a/part/icons/hi48-app-kxmleditor.png b/part/icons/hi48-app-kxmleditor.png Binary files differnew file mode 100644 index 0000000..50fe869 --- /dev/null +++ b/part/icons/hi48-app-kxmleditor.png diff --git a/part/icons/lo16-action-bookmark_next.png b/part/icons/lo16-action-bookmark_next.png Binary files differnew file mode 100644 index 0000000..12c0854 --- /dev/null +++ b/part/icons/lo16-action-bookmark_next.png diff --git a/part/icons/lo16-action-bookmark_prev.png b/part/icons/lo16-action-bookmark_prev.png Binary files differnew file mode 100644 index 0000000..4278292 --- /dev/null +++ b/part/icons/lo16-action-bookmark_prev.png diff --git a/part/icons/lo16-action-collapse_node.png b/part/icons/lo16-action-collapse_node.png Binary files differnew file mode 100644 index 0000000..3fa8bff --- /dev/null +++ b/part/icons/lo16-action-collapse_node.png diff --git a/part/icons/lo16-action-expand_node.png b/part/icons/lo16-action-expand_node.png Binary files differnew file mode 100644 index 0000000..82ee7ec --- /dev/null +++ b/part/icons/lo16-action-expand_node.png diff --git a/part/icons/lo16-action-xml_delete_attribute.png b/part/icons/lo16-action-xml_delete_attribute.png Binary files differnew file mode 100644 index 0000000..d63db43 --- /dev/null +++ b/part/icons/lo16-action-xml_delete_attribute.png diff --git a/part/icons/lo16-action-xml_delete_contents.png b/part/icons/lo16-action-xml_delete_contents.png Binary files differnew file mode 100644 index 0000000..da87e2a --- /dev/null +++ b/part/icons/lo16-action-xml_delete_contents.png diff --git a/part/icons/lo16-action-xml_delete_element.png b/part/icons/lo16-action-xml_delete_element.png Binary files differnew file mode 100644 index 0000000..4122060 --- /dev/null +++ b/part/icons/lo16-action-xml_delete_element.png diff --git a/part/icons/lo16-action-xml_delete_procins.png b/part/icons/lo16-action-xml_delete_procins.png Binary files differnew file mode 100644 index 0000000..ae65ec0 --- /dev/null +++ b/part/icons/lo16-action-xml_delete_procins.png diff --git a/part/icons/lo16-action-xml_edit_attribute.png b/part/icons/lo16-action-xml_edit_attribute.png Binary files differnew file mode 100644 index 0000000..aa176b1 --- /dev/null +++ b/part/icons/lo16-action-xml_edit_attribute.png diff --git a/part/icons/lo16-action-xml_edit_contents.png b/part/icons/lo16-action-xml_edit_contents.png Binary files differnew file mode 100644 index 0000000..770d7d8 --- /dev/null +++ b/part/icons/lo16-action-xml_edit_contents.png diff --git a/part/icons/lo16-action-xml_edit_element.png b/part/icons/lo16-action-xml_edit_element.png Binary files differnew file mode 100644 index 0000000..2a60632 --- /dev/null +++ b/part/icons/lo16-action-xml_edit_element.png diff --git a/part/icons/lo16-action-xml_edit_procins.png b/part/icons/lo16-action-xml_edit_procins.png Binary files differnew file mode 100644 index 0000000..080db82 --- /dev/null +++ b/part/icons/lo16-action-xml_edit_procins.png diff --git a/part/icons/lo16-action-xml_insert_attribute.png b/part/icons/lo16-action-xml_insert_attribute.png Binary files differnew file mode 100644 index 0000000..b87786c --- /dev/null +++ b/part/icons/lo16-action-xml_insert_attribute.png diff --git a/part/icons/lo16-action-xml_insert_contents.png b/part/icons/lo16-action-xml_insert_contents.png Binary files differnew file mode 100644 index 0000000..5a768fd --- /dev/null +++ b/part/icons/lo16-action-xml_insert_contents.png diff --git a/part/icons/lo16-action-xml_insert_element.png b/part/icons/lo16-action-xml_insert_element.png Binary files differnew file mode 100644 index 0000000..9421231 --- /dev/null +++ b/part/icons/lo16-action-xml_insert_element.png diff --git a/part/icons/lo16-action-xml_insert_procins.png b/part/icons/lo16-action-xml_insert_procins.png Binary files differnew file mode 100644 index 0000000..799e93a --- /dev/null +++ b/part/icons/lo16-action-xml_insert_procins.png diff --git a/part/icons/lo16-action-xml_move_item_down.png b/part/icons/lo16-action-xml_move_item_down.png Binary files differnew file mode 100644 index 0000000..30e0602 --- /dev/null +++ b/part/icons/lo16-action-xml_move_item_down.png diff --git a/part/icons/lo16-action-xml_move_item_up.png b/part/icons/lo16-action-xml_move_item_up.png Binary files differnew file mode 100644 index 0000000..7bb1b68 --- /dev/null +++ b/part/icons/lo16-action-xml_move_item_up.png diff --git a/part/icons/lo16-app-kxmleditor.png b/part/icons/lo16-app-kxmleditor.png Binary files differnew file mode 100644 index 0000000..5f8c3f2 --- /dev/null +++ b/part/icons/lo16-app-kxmleditor.png diff --git a/part/icons/lo32-app-kxmleditor.png b/part/icons/lo32-app-kxmleditor.png Binary files differnew file mode 100644 index 0000000..be1dac8 --- /dev/null +++ b/part/icons/lo32-app-kxmleditor.png diff --git a/part/kxe_treeview.cpp b/part/kxe_treeview.cpp new file mode 100644 index 0000000..f5bd08c --- /dev/null +++ b/part/kxe_treeview.cpp @@ -0,0 +1,909 @@ +/*************************************************************************** + kxe_treeview.cpp - description + ------------------- + begin : Thu Sep 20 2001 + copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team + email : OleBowle@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kxe_treeview.h" +#include "kxe_treeviewitem.h" +#include "kxesearchdialog.h" +#include "kxmleditorpart.h" + +#include "kxmleditorfactory.h" +#include "kxeconfiguration.h" +#include "kxetreeviewsettings.h" + +#include <klocale.h> +#include <kdebug.h> +#include <kxmlgui.h> +#include <kxmlguiclient.h> +#include <kpopupmenu.h> +#include <kglobalsettings.h> +#include <kmessagebox.h> + +// include files for Qt +#include "qdom_add.h" +#include <qheader.h> +#include <qdragobject.h> +#include <qtimer.h> +#include <qdom.h> +#include <qcursor.h> +#include <qevent.h> + +static const int autoOpenTimeout = 750; + + +KXE_TreeView::KXE_TreeView( KXMLGUIClient * pGUIClient, QWidget * pParent, const char * pszName ) + : KListView(pParent,pszName), + m_pGUIClient(pGUIClient), + m_nBookmarkedItems(0) +{ + setSorting(-1); // no sorting + + addColumn(i18n("Qualified name")); + + setSelectionMode(QListView::Single); + + connect( this, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()) ); + connect( this, SIGNAL(expanded(QListViewItem*)), this, SLOT(slotItemExpanded(QListViewItem*)) ); + + setReadWrite(false); + + m_bDrag = false; + m_pCurrentBeforeDropItem = 0; + m_pDropItem = 0; + + m_autoOpenTimer = new QTimer(this); + connect(m_autoOpenTimer, SIGNAL(timeout()), this, SLOT(slotAutoOpenFolder())); + + // Apply current configuration + slotTreeViewSettingsChanged(); + // and make sure to be informed about its changes. + connect( KXMLEditorFactory::configuration()->treeview(), SIGNAL(sigChanged()), this, SLOT(slotTreeViewSettingsChanged()) ); +} + +void KXE_TreeView::setReadWrite( bool fReadWrite ) +{ + setItemsRenameable( fReadWrite ); + setRenameable( 0, fReadWrite ); + + if ( fReadWrite ) // If the widget enters read/write mode, then enable/disable + { // dropping (according to the configuration data). + setAcceptDrops( KXMLEditorFactory::configuration()->treeview()->enableDropping() ); + viewport()->setAcceptDrops( KXMLEditorFactory::configuration()->treeview()->enableDropping() ); + } + else // If the widget enter read only mode, + { // then disable dropping. + setAcceptDrops( false ); + viewport()->setAcceptDrops( false ); + } +} + +////////////////////////////////////////////////////////////// +// configuration slots +////////////////////////////////////////////////////////////// + +void KXE_TreeView::slotTreeViewSettingsChanged() +{ + setRootIsDecorated( KXMLEditorFactory::configuration()->treeview()->decorateRoot() ); + + if ( KXMLEditorFactory::configuration()->treeview()->elemDisplMode() == KXETreeViewSettings::NoAttributes ) + { + if ( columns() > 1 ) + removeColumn(1); + } + else + { + if ( columns() < 2 ) + addColumn( i18n("Attributes") ); + } + + KXE_TreeViewItem * pItem = static_cast<KXE_TreeViewItem*> (firstChild()); + while (pItem) + { + pItem->setTexts(); + pItem = pItem->nextItem(); + } + + if ( itemsRenameable() ) // If the widget is in read/write mode, then enable/disable + { // dropping (according to the configuration data). + setAcceptDrops( KXMLEditorFactory::configuration()->treeview()->enableDropping() ); + viewport()->setAcceptDrops( KXMLEditorFactory::configuration()->treeview()->enableDropping() ); + } + +} + +////////////////////////////////////////////////////////////// +// action slots +////////////////////////////////////////////////////////////// + +void KXE_TreeView::editDeselect() +{ + clearSelection(); +} + +void KXE_TreeView::viewNodeUp() +{ + // get selected item from tree view + QListViewItem * pSelItem = selectedItem(); + if ( ! pSelItem ) + { + kdDebug() << "KXE_TreeView::slotViewNodeUp no item selected" << endl; + return; + } + + // get parent item + QListViewItem * pParentItem = pSelItem->parent(); + + // select parent item in tree view + if (pParentItem) + { + setCurrentItem(pParentItem); + ensureItemVisible(pParentItem); + } +} + +void KXE_TreeView::viewExpNode( int nLevel ) +{ + // get selected item from tree view (if any) + QListViewItem * pSelItem = selectedItem(); + if ( ! pSelItem ) + { + kdDebug() << "KXE_TreeView::slotViewExpNode no item selected" << endl; + return; + } + + // expand node + KXE_TreeViewItem * pSelTreeItem = static_cast <KXE_TreeViewItem*> (pSelItem); + pSelTreeItem->expandSubTree(nLevel); +} + +void KXE_TreeView::viewColNode( int nLevel ) +{ + // get selected item from tree view (if any) + QListViewItem * pSelItem = selectedItem(); + if ( ! pSelItem ) + { + kdDebug() << "KXE_TreeView::slotViewColNode no item selected" << endl; + return; + } + + // expand node + KXE_TreeViewItem * pSelTreeItem = static_cast <KXE_TreeViewItem*> (pSelItem); + pSelTreeItem->collapseSubTree(nLevel); +} + +void KXE_TreeView::bookmarksToggle() +{ + // get selected item from tree view + KXE_TreeViewItem * pSelItem = static_cast <KXE_TreeViewItem*> (selectedItem()); + if ( ! pSelItem ) + { + kdDebug() << "KXE_TreeView::bookmarksToggle: no item selected" << endl; + return; + } + + // toggle bookmark on selected item + if(pSelItem->toggleBookmark()) + m_nBookmarkedItems++; + else + m_nBookmarkedItems--; +} + +void KXE_TreeView::bookmarksPrev() +{ + if ( childCount() < 1 ) + { + kdDebug() << "KXE_TreeView::bookmarksPrev: internal error - this tree view is empty" << endl; + return; + } + + // get selected item from tree view + KXE_TreeViewItem * pSelItem = static_cast <KXE_TreeViewItem*> (selectedItem()); + if ( ! pSelItem ) // If there is no item selected we take + { // the last root items last grand child. + QListViewItem * pTmpItem = firstChild(); // Take first child and + while ( pTmpItem->nextSibling() ) // find last child by + pTmpItem = pTmpItem->nextSibling(); // traversing all childs + + pSelItem = static_cast <KXE_TreeViewItem*> (pTmpItem); // this is the last root item + while ( pSelItem->lastChild() ) // find its last + pSelItem = pSelItem->lastChild(); // grand child + + if ( pSelItem->isBookmarked() ) // We have to check its + { // bookmarked-status + selectItem(pSelItem); // and select it, in case + return; // it is bookmarked. + } + } + + // Search items above the selected one + while ( (pSelItem = pSelItem->prevItem()) != 0 ) + { + if ( pSelItem->isBookmarked() ) + { + selectItem(pSelItem); + return; + } + } +} + +void KXE_TreeView::bookmarksNext() +{ + if ( childCount() < 1 ) + { + kdDebug() << "KXE_TreeView::bookmarksNext: internal error - this tree view is empty" << endl; + return; + } + + // get selected item from tree view + KXE_TreeViewItem * pSelItem = static_cast <KXE_TreeViewItem*> (selectedItem()); + if ( ! pSelItem ) + { // If there is no item selected + pSelItem = static_cast <KXE_TreeViewItem*> (firstChild()); // we take the first root item, + if ( pSelItem->isBookmarked() ) // but we have to check its + { // bookmarked-status + selectItem(pSelItem); // and select it, in case + return; // it is bookmarked. + } + } + + // Search items below the selected one + while ( (pSelItem = pSelItem->nextItem()) != 0 ) + { + if ( pSelItem->isBookmarked() ) + { + selectItem(pSelItem); + return; + } + } +} + +void KXE_TreeView::selectItem( KXE_TreeViewItem * const pItem ) +{ + if ( ! pItem ) + { + kdDebug() << "KXE_TreeView::selectItem: the given pointer is a null pointer" << endl; + return; + } + + setSelected( pItem, true ); + setCurrentItem( pItem ); + ensureItemVisible( pItem ); +} + +bool KXE_TreeView::selectNode( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdError() << "KXE_TreeView::selectNode: the given node is an empty one" << endl; + return false; + } + + KXE_TreeViewItem * pItem = findCorrespondingItem(node); + + if ( ! pItem ) // can't find the corresponding item + { + kdError() << "KXE_TreeView::selectNode can't find an item to the given node." << endl; + return false; + } + + selectItem(pItem); + return true; +} + +QDomNode * KXE_TreeView::getSelectedNode() const +{ + // get selected item from tree view + QListViewItem * pSelItem = selectedItem(); + if ( ! pSelItem ) + return 0; + + KXE_TreeViewItem * pSelTreeItem = static_cast <KXE_TreeViewItem *> (pSelItem); + return pSelTreeItem->xmlNode(); +} + +QDomNode * KXE_TreeView::getSpecProcInstrNode(const QString& target) const +{ + KXE_TreeViewItem * pTreeItem = static_cast<KXE_TreeViewItem*> (firstChild()); + while ( pTreeItem ) + { + if (pTreeItem->xmlNode()->isProcessingInstruction()) + { + QDomProcessingInstruction domProcInstr = pTreeItem->xmlNode()->toProcessingInstruction(); + if(domProcInstr.target() == target) + return pTreeItem->xmlNode(); + } + + pTreeItem = pTreeItem->nextItem(); + } + + return 0; +} + +// Return info, is root element is already created +bool KXE_TreeView::hasRootNode() +{ + KXE_TreeViewItem * pTreeItem = static_cast<KXE_TreeViewItem*> (firstChild()); + while ( pTreeItem ) + { + if (pTreeItem->xmlNode()->isElement()) + { + return true; + } + + pTreeItem = pTreeItem->nextItem(); + } + + return false; +} + + +QString KXE_TreeView::getSelectedPath() const +{ + // get selected item from tree view + QListViewItem * pSelItem = selectedItem(); + if ( ! pSelItem ) + return QString(); + + KXE_TreeViewItem * pSelTreeItem = static_cast <KXE_TreeViewItem *> (pSelItem); + return domTool_getPath( * pSelTreeItem->xmlNode() ); +} + +void KXE_TreeView::contentsMousePressEvent( QMouseEvent * pEvent ) +{ + KListView::contentsMousePressEvent(pEvent); + + if ( pEvent->button() == RightButton ) + { + QString szMenuName; + + QListViewItem * pItem = itemAt( contentsToViewport(pEvent->pos()) ); + if (pItem) + { + KXE_TreeViewItem * pTreeItem = static_cast <KXE_TreeViewItem*> (pItem); + switch( pTreeItem->xmlNode()->nodeType() ) + { + case QDomNode::ElementNode: + szMenuName = "popupXmlElement"; + break; + case QDomNode::TextNode: + case QDomNode::CDATASectionNode: + case QDomNode::CommentNode: + szMenuName = "popupXmlContent"; + break; + case QDomNode::ProcessingInstructionNode: + szMenuName = "popupXmlProcInstr"; + break; + default: + kdDebug() << "KXE_TreeView::contentsMousePressEvent unknown item type" << endl; + return; + } + } + else + szMenuName = "popupXmlTree"; + + emit sigContextMenuRequested( szMenuName, QCursor::pos() ); + return; + } + + //--- Drag & Drop ------------------------------------------------------ + QPoint p(contentsToViewport(pEvent->pos())); + QListViewItem *i = itemAt(p); + + if(pEvent->button() == LeftButton && i) + { // if the user clicked into the root decoration of the item, don't try to start a drag! + if(p.x() > header()->cellPos(header()->mapToActual(0)) + + treeStepSize() * ( i->depth() + (rootIsDecorated() ? 1 : 0)) + itemMargin() || + p.x() < header()->cellPos(header()->mapToActual(0))) + { + m_dragPos = pEvent->pos(); + m_bDrag = true; + } + } +} + +void KXE_TreeView::slotSelectionChanged() +{ + KXE_TreeViewItem * pItem = static_cast <KXE_TreeViewItem*> (selectedItem()); + + if ( ! pItem ) + emit sigSelectionCleared(hasRootNode()); + else + { + QDomNode selectedNode = * ( pItem->xmlNode() ); // uses QDomNode copy constructor + + // choose appropriate object kind + switch ( selectedNode.nodeType() ) + { + case QDomNode::ElementNode: + emit sigSelectionChanged( selectedNode.toElement()); + break; + + case QDomNode::TextNode: + case QDomNode::CDATASectionNode: + case QDomNode::CommentNode: + emit sigSelectionChanged( selectedNode.toCharacterData()); + break; + + case QDomNode::ProcessingInstructionNode: + emit sigSelectionChanged( selectedNode.toProcessingInstruction()); + break; + + default: + kdDebug() << "KXE_TreeView::slotSelectionChanged unknown object type selected" << endl; + return; + } + } +} + + +void KXE_TreeView::slotItemExpanded( QListViewItem * pItem ) +{ + KXE_TreeViewItem * pTreeViewItem = static_cast<KXE_TreeViewItem*> (pItem); + pTreeViewItem->ensureGrandChildItemsCreated(); +} + + +////////////////////////////////////////////////////////////// +// update slots +////////////////////////////////////////////////////////////// + +void KXE_TreeView::updateNodeCreated( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdError() << "KXE_TreeView::slotUpdateNodeCreated the given node is an empty one." << endl; + return; + } + + KXE_TreeViewItem * pNewItem; + if ( node.parentNode().isDocument() ) // the new nodes parent is the document itself, + { + // so we have to create a root item. + // Now it depends: either it's a processing instruction, or element + if (node.isProcessingInstruction()) + // Tree looks much nicer if root processing instructions are ont the top... + { + QDomNode *pNode = getSpecProcInstrNode("xml"); + if (pNode) + pNewItem = new KXE_TreeViewItem( node, this,findCorrespondingItem(*pNode)); + else + pNewItem = new KXE_TreeViewItem( node, this); + } + else + // ...and root element is placed at the bottom. + pNewItem = new KXE_TreeViewItem( node, this,lastChild()); +// pNewItem = new KXE_TreeViewItem( node, this); + + if ( ! rootIsDecorated() ) + pNewItem->setOpen(true); + } + else + { + if ( node.parentNode().isNull() ) + { + kdError() << "KXE_TreeView::slotUpdateNodeCreated the given node has no parent node (but should)." << endl; + return; + } + + // To create the new item, we need (1st) the item corresponding to the parent node of the given one. + QDomNode parentNode = node.parentNode(); + // Because the currently selected item is very likely (in many cases) the correct one, try it first. + KXE_TreeViewItem * pParentItem = static_cast<KXE_TreeViewItem*> (selectedItem()); + if ( (!pParentItem) || ( *(pParentItem->xmlNode()) != parentNode ) ) + { // no strike :-( + pParentItem = findCorrespondingItem(parentNode); // do it the "long" way + } + + if ( ! pParentItem ) // can't find the corresponding item + { + kdError() << "KXE_TreeView::slotUpdateNodeCreated can't find an item to the given nodes parent node." << endl; + return; + } + + // Now we need (2nd) the item corresponding to the previous sibling of the given one, + // because, the new item has to be inserted behind the given one. + QDomNode prevNode = node.previousSibling(); + if ( prevNode.isNull() ) + { // it seems to be the first child node, so create a first child item + pNewItem = new KXE_TreeViewItem( node, pParentItem ); + } + else + { + KXE_TreeViewItem * pPrevItem = findCorrespondingItem(prevNode); + if ( ! pParentItem ) // can't find the corresponding item :-( + { + kdError() << "KXE_TreeView::slotUpdateNodeCreated can't find an item to the given nodes previous sibling." << endl; + return; + } + // everything's alright, let's create the new item + pNewItem = new KXE_TreeViewItem( node, pParentItem, pPrevItem ); + } + + } + + setSelected( pNewItem, true ); + ensureItemVisible( pNewItem ); +} + +void KXE_TreeView::updateNodeChanged( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdError() << "KXE_TreeView::slotUpdateNodeChanged the given node is an empty one." << endl; + return; + } + + // To change the item, we have to find it. + // Because the currently selected item is very likely (in many cases) the correct one, try it first. + KXE_TreeViewItem * pItem = static_cast<KXE_TreeViewItem*> (selectedItem()); + if ( (!pItem) || ( *(pItem->xmlNode()) != node ) ) // no strike :-( + pItem = findCorrespondingItem(node); // do it the "long" way + + if ( ! pItem ) // can't find the corresponding item + { + kdError() << "KXE_TreeView::slotUpdateNodeChanged can't find an item to the given node." << endl; + return; + } + + pItem->setTexts(); // update the item + + setSelected( pItem, true ); + ensureItemVisible( pItem ); +} + +void KXE_TreeView::updateNodeDeleted( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdError() << "KXE_TreeView::slotUpdateNodeDeleted the given node is an empty one." << endl; + return; + } + + // To remove the item, we have to find it. + // Because the currently selected item is very likely (in many cases) the correct one, try it first. + KXE_TreeViewItem * pItem = static_cast<KXE_TreeViewItem*> (selectedItem()); + if ( (!pItem) || ( *(pItem->xmlNode()) != node ) ) // no strike :-( + pItem = findCorrespondingItem(node); // do it the "long" way + + if ( ! pItem ) // can't find the corresponding item + { + kdError() << "KXE_TreeView::slotUpdateNodeDeleted can't find an item to the given node." << endl; + return; + } + + clearSelection(); + + delete pItem; + + emit sigSelectionCleared(hasRootNode()); +} + +void KXE_TreeView::updateNodeMoved( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdError() << "KXE_TreeView::slotUpdateNodeMoved the given node is an empty one." << endl; + return; + } + + // To move the item, we have to find it. + // Because the currently selected item is very likely (in many cases) the correct one, try it first. + KXE_TreeViewItem * pItem = static_cast<KXE_TreeViewItem*> (selectedItem()); + if ( (!pItem) || ( *(pItem->xmlNode()) != node ) ) // no strike :-( + pItem = findCorrespondingItem(node); // do it the "long" way + + if ( ! pItem ) // can't find the corresponding item + { + kdError() << "KXE_TreeView::slotUpdateNodeMoved can't find an item to the given node." << endl; + return; + } + + // Now we can move the item (of the moved node). + // We have to differenciate between the following 2 cases. + if ( node.previousSibling().isNull() ) + { + // The node does not has a previous sibling. This means, it has been moved + // to be its parent first child. In this case, we have to find the tree + // view item of the node's next sibling to swap them. + // It's very likely the previous sibling of the item corresponding to the + // moved node. + KXE_TreeViewItem * pOldPrevItem = pItem->prevSibling(); + // Was it really? + if ( ! pOldPrevItem || ( *(pOldPrevItem->xmlNode()) != node.nextSibling() ) ) + // It wasn't (how can it be?) - we have to find it using the "long" way. + pOldPrevItem = findCorrespondingItem( node.nextSibling() ); + + if ( ! pOldPrevItem ) // something went wrong + { + kdError() << "KXE_TreeView::slotUpdateNodeMoved can't find the item to the given node's next sibling." << endl; + return; + } + + // Now we can swap them (make the old previous item the new next item of + // the moved node's item). + pOldPrevItem->moveItem( pItem ); + } + else + { + // The node has a previous sibling. In this case we have to find the + // corresponding tree view item to swap it with the item corresponding to + // the moved node. + KXE_TreeViewItem * pNewPrevItem = findCorrespondingItem( node.previousSibling() ); + if ( ! pNewPrevItem ) + { + kdError() << "KXE_TreeView::slotUpdateNodeMoved can't find the new prev.item to the given nodes prev.node." << endl; + return; + } + + // swap them (move the moved node's item after the previous sibling's item) + pItem->moveItem( pNewPrevItem ); + } + + setSelected( pItem, true ); + ensureItemVisible( pItem ); +} + +void KXE_TreeView::updateClear() +{ + clear(); +} + +void KXE_TreeView::rename( QListViewItem * pItem, int nColumn ) +{ + if ( nColumn != 0 ) // inplace editing only + return; // for the first column + + KXE_TreeViewItem * pXMLItem = static_cast <KXE_TreeViewItem*> (pItem); + if ( pXMLItem->xmlNode()->isElement() ) // inplace-renaming only for items representing XML elements + KListView::rename( pItem, nColumn ); // inplace-renaming via base class functionality + + else if(pXMLItem->xmlNode()->isCharacterData()) // launch dialog for editing text nodes + (dynamic_cast <KXMLEditorPart *> (m_pGUIClient))->slotXmlCharDataEdit(); + + else if(pXMLItem->xmlNode()->isProcessingInstruction()) // launch dialog for editing proc.instr. + (dynamic_cast <KXMLEditorPart *> (m_pGUIClient))->slotXmlProcInstrEdit(); +} + +////////////////////////////////////////////////////////////// +// misc functions +////////////////////////////////////////////////////////////// + +KXE_TreeViewItem * KXE_TreeView::findCorrespondingItem( const QDomNode & node ) +{ + KXE_TreeViewItem * pItem = static_cast<KXE_TreeViewItem*> (firstChild()); + while ( pItem ) + { + if ( *(pItem->xmlNode()) == node ) + return pItem; + pItem = pItem->nextItem(); + } + + return 0; +} + +////////////////////////////////////////////////////////////// +// Drag & Drop +////////////////////////////////////////////////////////////// + +/** Overrides KListView::contentsMouseMoveEvent */ +void KXE_TreeView::contentsMouseMoveEvent(QMouseEvent *e) +{ + KListView::contentsMouseMoveEvent(e); + + // exit, if dragging is disabled + if ( ! KXMLEditorFactory::configuration()->treeview()->enableDragging() ) + return; + + if(!m_bDrag || (e->pos() - m_dragPos).manhattanLength() <= KGlobalSettings::dndEventDelay()) + return; + + m_bDrag = false; + + QListViewItem *item = itemAt(contentsToViewport(m_dragPos)); + + if(!item || !item->isSelectable()) + return; + + // copy item into clipboard + KXE_TreeViewItem *pXmlTreeItem = static_cast <KXE_TreeViewItem *> (item); + QTextDrag *pDrag = (dynamic_cast <KXMLEditorPart *> (m_pGUIClient))->copyNode(pXmlTreeItem->xmlNode()); + + + // Start a drag + const QPixmap *pix = item->pixmap(0); + if(pix && pDrag->pixmap().isNull()) + { QPoint hotspot(pix->width() / 2, pix->height() / 2); + pDrag->setPixmap(*pix, hotspot); + } + + pDrag->drag(); +} + +/** Overrides KListView::contentsMouseReleaseEvent */ +void KXE_TreeView::contentsMouseReleaseEvent(QMouseEvent *e) +{ + KListView::contentsMouseReleaseEvent(e); + m_bDrag = false; +} + +/** Overrides QScrollView::contentsDragEnterEvent */ +void KXE_TreeView::contentsDragEnterEvent(QDragEnterEvent *e) +{ + m_pDropItem = 0; + m_pCurrentBeforeDropItem = selectedItem(); + + // Save the available formats + m_lstDropFormats.clear(); + for(int i = 0; e->format(i); i++) + { if(*(e->format(i))) + { m_lstDropFormats.append(e->format(i)); + } + } +} + +/** Overrides QScrollView::contentsDragMoveEvent */ +void KXE_TreeView::contentsDragMoveEvent(QDragMoveEvent *e) +{ + QListViewItem *item = itemAt(contentsToViewport(e->pos())); + + // Accept drops on the background, if Texts + if(!item && (m_lstDropFormats.contains("text/"))) + { m_pDropItem = 0; + e->acceptAction(); + if(selectedItem()) + setSelected(selectedItem(), false); // no item selected + return; + } + + if(!item || !item->isSelectable()) + { m_pDropItem = 0; + m_autoOpenTimer->stop(); + e->ignore(); + return; + } + + e->acceptAction(); + + setSelected(item, true); + + if(item != m_pDropItem ) + { m_autoOpenTimer->stop(); + m_pDropItem = item; + m_autoOpenTimer->start(autoOpenTimeout); + } +} + +/** Overrides QScrollView::contentsDragLeaveEvent */ +void KXE_TreeView::contentsDragLeaveEvent(QDragLeaveEvent *e) +{ + e=e; + // Restore the current item to what it was before the dragging (#17070) + if(m_pCurrentBeforeDropItem) + setSelected(m_pCurrentBeforeDropItem, true); + else + setSelected(m_pDropItem, false); // no item selected + + m_pCurrentBeforeDropItem = 0; + m_pDropItem = 0; + m_lstDropFormats.clear(); +} + +/** Overrides QScrollView::contentsDropEvent */ +void KXE_TreeView::contentsDropEvent(QDropEvent *pDropEvent) +{ + m_autoOpenTimer->stop(); + + drop(selectedItem(), pDropEvent); +} + +/** Called, when m_autoOpenTimer timeout occured */ +void KXE_TreeView::slotAutoOpenFolder() +{ + m_autoOpenTimer->stop(); + + if(!m_pDropItem || m_pDropItem->isOpen()) + return; + + m_pDropItem->setOpen( true ); + m_pDropItem->repaint(); +} + +/** Drop or paste text into item */ +bool KXE_TreeView::drop(QListViewItem *pItem, QDropEvent *pDropEvent) +{ + KXE_TreeViewItem* pTreeItem = 0; + if(pItem) + pTreeItem = static_cast <KXE_TreeViewItem *> (pItem); + + QDomNode *pTargetNode = pTreeItem->xmlNode(); + + // First, make check, if moved item is not moved to their children + if((pDropEvent->source() == this) && (pDropEvent->action() == QDropEvent::Move)) + { // make check, if moved item is not moved to itself + if(m_pCurrentBeforeDropItem && pTreeItem && (m_pCurrentBeforeDropItem == pTreeItem)) + { return false; + } + + if(m_pCurrentBeforeDropItem && pTreeItem && + static_cast <KXE_TreeViewItem*> (m_pCurrentBeforeDropItem)->isMyChildren(pTreeItem)) + { KMessageBox::sorry(0, i18n("An XML element can't be moved to its own subtree.")); + return false; + } + + if (pTreeItem->xmlNode()->isProcessingInstruction()) + { + KMessageBox::sorry(0, i18n("An XML node can't be moved in a processing instruction.")); + return false; + } + + QDomNode * pNode = static_cast <KXE_TreeViewItem*> (m_pCurrentBeforeDropItem)->xmlNode(); + if (pNode->isProcessingInstruction()) + { + QDomProcessingInstruction domProcInstr = pNode->toProcessingInstruction(); + + if(domProcInstr.target() == "xml") + { KMessageBox::sorry(0, i18n("This processing instruction cannot be moved !")); + return false; + } + } + } + + //-- If Move from same instance of this widget + if((pDropEvent->source() == this) && (pDropEvent->action() == QDropEvent::Move) && (m_pCurrentBeforeDropItem) && pTargetNode->isElement()) + { + // remove source item + QDomNode * pSourceNode = static_cast <KXE_TreeViewItem*> (m_pCurrentBeforeDropItem)->xmlNode(); + QDomElement domTargetElement = pTargetNode->toElement(); + + if((dynamic_cast <KXMLEditorPart *> (m_pGUIClient))->dropMoveNode(domTargetElement, *pSourceNode)) + { + pDropEvent->acceptAction(); + return true; + } + } + else + { + //-- If Copy, do standart Paste function + if((dynamic_cast <KXMLEditorPart *> (m_pGUIClient))->pasteNode(pTargetNode, pDropEvent)) + { + pDropEvent->acceptAction(); + return true; + } + } + return false; +} + + +// +// returns last child on the tree (top-level) +// +KXE_TreeViewItem* KXE_TreeView::lastChild() +{ + QListViewItem* pItem = firstChild(); + if (pItem && pItem->nextSibling()) + do + pItem = pItem->nextSibling(); + while (pItem->nextSibling()); + + // here we have it... + return (KXE_TreeViewItem*) pItem; +} + +void KXE_TreeView::keyPressEvent(QKeyEvent *e) +{ + KListView::keyPressEvent(e); + emit sigKeyPressed(e); +} diff --git a/part/kxe_treeview.h b/part/kxe_treeview.h new file mode 100644 index 0000000..0ba2c86 --- /dev/null +++ b/part/kxe_treeview.h @@ -0,0 +1,235 @@ +/*************************************************************************** + kxe_treeview.h - description + ------------------- + begin : Thu Sep 20 2001 + copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team + email : OleBowle@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KXE_TREEVIEW_H +#define KXE_TREEVIEW_H + +#include <klistview.h> +#include <qstrlist.h> + +class KXESearchDialog; + +class QDomDocument; +class QDomNode; +class QDomElement; +class QDomCharacterData; +class QDomProcessingInstruction; + +class QMouseEvent; +class QTimer; +class QKeyEvent; +class KXMLGUIClient; +class KXE_TreeViewItem; + +/** + * This is a listview, which displays the XML tree structure. + * @short shows XML tree + */ +class KXE_TreeView : public KListView +{ + Q_OBJECT + +public: + KXE_TreeView( KXMLGUIClient * pGUIClient, QWidget * pParent = 0, const char * pszName = 0 ); + + /** Changes the behaviour of this view to readonly or readwrite. */ + void setReadWrite( bool fReadWrite ); + + /** Selects the given item. */ + void selectItem( KXE_TreeViewItem * const pItem ); + + /** Selects the item corresponding to the given node. + * Returns true on success, false otherwise. */ + bool selectNode( const QDomNode & node ); + + /** Returns the a pointer to the selected items node or a null pointer (if no item is selected). */ + QDomNode * getSelectedNode() const; + + /** Returns the a pointer to the special processing instruction or a null pointer for (if no item is exists). */ + QDomNode * getSpecProcInstrNode(const QString& target) const; + + /** Returns the selected items path or an empty string, if no item is selected. */ + QString getSelectedPath() const; + + /** Returns true, if this tree view contains bookmarked tree items and false otherwise. */ + bool containsBookmarkedItems() const { return (m_nBookmarkedItems>0); } + + /** Drop or paste text into item */ + bool drop(QListViewItem *, QDropEvent *); + + /** toggles bookmark on the selected item */ + void bookmarksToggle(); + + /** searches for the next bookmarked item */ + void bookmarksPrev(); + + /** searches for the previous bookmarked item */ + void bookmarksNext(); + + /** deselects currently selected item */ + void editDeselect(); + + /** Selects the selected item's parent item. */ + void viewNodeUp(); + + /** Expands the selected tree item's subtree to the given level (see @ref KXE_TreeViewItem::expandSubTree). */ + void viewExpNode( int nLevel ); + + /** Collapses the selected tree item's subtree to the given level (see @ref KXE_TreeViewItem::collapseSubTree). */ + void viewColNode( int nLevel ); + + /** + * Creates new item(s) to the given node (and its child nodes) + * and inserts it (or them) in the tree. + */ + void updateNodeCreated( const QDomNode & node ); + + /** Changes the item corresponding to the given node. */ + void updateNodeChanged( const QDomNode & node ); + + /** Removes the item corresponding to the given node. */ + void updateNodeDeleted( const QDomNode & node ); + + /** Moves the item corresponding to the given node. */ + void updateNodeMoved( const QDomNode & node ); + + /** Clears the whole tree. */ + void updateClear(); + + /** + * Handles inplace-renaming of items, because in our case + * only items representing XML elements are to be renameable. + * For the actual renaming of the items text, the base + * class functionality is used and the signal + * @ref sigItemRenamedInplace emitted. + */ + virtual void rename( QListViewItem * pItem, int nColumn ); + + /** Returns info, is root element is already created */ + bool hasRootNode(); + /** Returns last top-level child on the tree. If there are no chold in the tree, null is returned. */ + KXE_TreeViewItem* lastChild(); + +public slots: + + // configuration slots + ////////////////////////////////////////////////////////////// + + /** + * Changes this tree view's settings according to the current + * configuration. + */ + void slotTreeViewSettingsChanged(); + +signals: + /** emitted, when no item is selected */ + void sigSelectionCleared(bool); + + /** emitted, when an XML element item is selected */ + void sigSelectionChanged( const QDomElement & ); + + /** emitted, when an XML Content item is selected */ + void sigSelectionChanged( const QDomCharacterData & ); + + /** emitted, when an XML proc.instr. item is selected */ + void sigSelectionChanged( const QDomProcessingInstruction & ); + + /** + * Signals the change of bookmark status. + * true - item(s) bookmarked + * false - no item bookmarked + */ + void sigNewBookmarkStatus( bool fStatus ); + + /** Emitted, when a context menu is requested */ + void sigContextMenuRequested( const QString & szMenuName, const QPoint & pos ); + /** Emitted when user presses a key. */ + void sigKeyPressed(QKeyEvent* e); + +protected: + /** if RMB shows the popupmenu corresponding to the selected item */ + void contentsMousePressEvent( QMouseEvent * ); + + /** Finds the corresponding treeview item to the given node. */ + KXE_TreeViewItem * findCorrespondingItem( const QDomNode & node ); + + /** Overrides KListView::contentsMouseReleaseEvent */ + void contentsMouseReleaseEvent(QMouseEvent *); + + /** Overrides KListView::contentsMouseMoveEvent */ + void contentsMouseMoveEvent(QMouseEvent *); + + /** Overrides QScrollView::contentsDragEnterEvent */ + void contentsDragEnterEvent(QDragEnterEvent *); + + /** Overrides QScrollView::contentsDragMoveEvent */ + void contentsDragMoveEvent(QDragMoveEvent *); + + /** Overrides QScrollView::contentsDragLeaveEvent */ + void contentsDragLeaveEvent(QDragLeaveEvent *); + + /** Overrides QScrollView::contentsDropEvent */ + void contentsDropEvent(QDropEvent *); + virtual void keyPressEvent(QKeyEvent *e); + +protected slots: + /** Checks, which type of item was selected an emits the corresponding signal. */ + void slotSelectionChanged(); + /** + * Ensures that the expanded item's grandchild items are created. + * This is very important for the "create items on demand" mode. But even in + * "create all items while loading" mode, this function has to be executed, + * because KXMLEditor could have been in "create items on demand" mode during + * the opening of the document. + * + * To be connected to the signal QListView::expanded(QListViewItem*). + */ + void slotItemExpanded( QListViewItem * ); + +private slots: + + /** Called, when m_autoOpenTimer timeout occured */ + void slotAutoOpenFolder(); + +protected: + + /** the GUI client, needed for the popupmenus */ + KXMLGUIClient * m_pGUIClient; + + /** number of bookmarked items */ + unsigned int m_nBookmarkedItems; + + /** True if drag&drop operation started, otherwise is false */ + bool m_bDrag; + + /** Contain mouse position of drag operation */ + QPoint m_dragPos; + + /** The item that was current before the drag-enter event happened */ + QListViewItem *m_pCurrentBeforeDropItem; + + /** The item we are moving the mouse over (during a drag) */ + QListViewItem *m_pDropItem; + + /** List of avalilable drop formats */ + QStrList m_lstDropFormats; + + /** Timer for counting time to auto open fselected folder while drag */ + QTimer *m_autoOpenTimer; +}; + +#endif diff --git a/part/kxe_treeviewitem.cpp b/part/kxe_treeviewitem.cpp new file mode 100644 index 0000000..0107bee --- /dev/null +++ b/part/kxe_treeviewitem.cpp @@ -0,0 +1,330 @@ +/*************************************************************************** + kxe_treeviewitem.cpp - description + ------------------- + begin : Wed Nov 21 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 "kxe_treeviewitem.h" + +#include "kxmleditorfactory.h" +#include "kxeconfiguration.h" +#include "kxetreeviewsettings.h" + +#include "qdom_add.h" + +#include <qregexp.h> + +#include <klistview.h> +#include <kdebug.h> +#include <kiconloader.h> + +KXE_TreeViewItem::KXE_TreeViewItem( const QDomNode & xmlNode, QListViewItem * pParent ) + : QListViewItem(pParent), + m_xmlNode(xmlNode), + m_pPrevSibling(0), + m_bBookmarked(false), + m_bChildsCreated(false), + m_bGrandChildsCreated(false) +{ + init(); + initChilds(); +} + +KXE_TreeViewItem::KXE_TreeViewItem( const QDomNode & xmlNode, KListView * pParent, QListViewItem* pAfter) + : QListViewItem(pParent,pAfter), + m_xmlNode(xmlNode), + m_pPrevSibling(0), + m_bBookmarked(false), + m_bChildsCreated(false), + m_bGrandChildsCreated(false) +{ + init(); + initChilds(); +} + +KXE_TreeViewItem::KXE_TreeViewItem( const QDomNode & xmlNode, QListViewItem * pParent, QListViewItem * pAfter ) + : QListViewItem( pParent, pAfter ), + m_xmlNode(xmlNode), + m_pPrevSibling(0), + m_bBookmarked(false), + m_bChildsCreated(false), + m_bGrandChildsCreated(false) +{ + init(); + initChilds(); +} + +KXE_TreeViewItem::~KXE_TreeViewItem() +{ + // inform the next sibling (if there's any) about destroying this item (as its previous sibling) + KXE_TreeViewItem * pNextItem = static_cast <KXE_TreeViewItem*> (nextSibling()); + if ( pNextItem ) + { pNextItem->setPrevSibling(m_pPrevSibling); + } +} + +void KXE_TreeViewItem::init() +{ + // A tree view item can only be in-place renameable, if it represents an XML element + // (the final check occurs in KXE_TreeViewItem::startRename). + if ( m_xmlNode.isElement() ) + setRenameEnabled( 0, true ); + + // inform the next sibling (if there's any) about this item (as its previous sibling) + KXE_TreeViewItem * pNextItem = static_cast <KXE_TreeViewItem*> (nextSibling()); + if ( pNextItem ) + pNextItem->setPrevSibling(this); + + setPixmap(0, domTool_getIconForNodeType(m_xmlNode.nodeType(), false)); + + if ( domTool_getLevel(m_xmlNode) < (unsigned int)KXMLEditorFactory::configuration()->treeview()->dfltExpLevel() ) + setOpen(true); + + setTexts(); +} + +void KXE_TreeViewItem::setTexts() +{ + switch ( m_xmlNode.nodeType() ) + { + case QDomNode::ElementNode: + + setText( 0, m_xmlNode.toElement().nodeName() ); + + if ( KXMLEditorFactory::configuration()->treeview()->elemDisplMode() == KXETreeViewSettings::NoAttributes ) + setText( 1, QString() ); + else + { + // parse all attributes to fill the second column + QString str2ndCol; + for ( uint i=0; i < m_xmlNode.toElement().attributes().length(); i++ ) + { + if ( i > 0 ) + str2ndCol += ", "; + str2ndCol += m_xmlNode.toElement().attributes().item(i).toAttr().name(); + if ( KXMLEditorFactory::configuration()->treeview()->elemDisplMode() == KXETreeViewSettings::NamesAndValues ) + str2ndCol += '=' + m_xmlNode.toElement().attributes().item(i).toAttr().value(); + } + setText( 1, str2ndCol ); + } + break; + + case QDomNode::TextNode: + case QDomNode::CDATASectionNode: + case QDomNode::CommentNode: + { + // set name + QString strText = m_xmlNode.toCharacterData().data(); + strText = strText.replace( QRegExp("\n"), " " ); // replace every newline by a space + strText = strText.replace( QRegExp("\t"), "" ); // removes every tab + strText = strText.replace( QRegExp("\r"), "" ); // removes every return + strText = strText.simplifyWhiteSpace(); + if( strText.length() > 30 ) // reduce name length, if necessary + strText = strText.left(30) + "..."; + setText( 0, strText ); + + break; + } + + case QDomNode::ProcessingInstructionNode: + + setText( 0, m_xmlNode.toProcessingInstruction().target() ); + break; + + default: + kdDebug() << "KXE_TreeViewItem::init: unknown node type (" << m_xmlNode.nodeType() << ")" << endl; + } +} + +void KXE_TreeViewItem::initChilds() +{ + if ( ! KXMLEditorFactory::configuration()->treeview()->createItemsOnDemand() || + ( ! m_bChildsCreated && + ( ! parent() || ( parent() && parent()->isOpen() ) ) + ) + ) + ensureChildItemsCreated(); +} + +bool KXE_TreeViewItem::toggleBookmark() +{ + m_bBookmarked = ! m_bBookmarked; + + setPixmap(0, domTool_getIconForNodeType(m_xmlNode.nodeType(), m_bBookmarked)); + + return m_bBookmarked; +} + +KXE_TreeViewItem * KXE_TreeViewItem::lastChild() const +{ + // take the first child + QListViewItem * pTmpItem = firstChild(); + // if there are no childs return 0 + if ( ! pTmpItem ) + return 0; + + QListViewItem * pTmpItem2; + while ( (pTmpItem2 = pTmpItem->nextSibling()) != 0 ) // traversing all childs + { + pTmpItem = pTmpItem2; + } + + return static_cast <KXE_TreeViewItem*> (pTmpItem); +} + +KXE_TreeViewItem * KXE_TreeViewItem::prevItem() +{ + if ( m_pPrevSibling ) // if there is a prev. sibling + { // return its last grand child (if there is any) + KXE_TreeViewItem * pPrevItem = m_pPrevSibling; + KXE_TreeViewItem * pTmpItem; + while ( (pTmpItem=pPrevItem->lastChild()) ) + pPrevItem = pTmpItem; + return pPrevItem; + } + else // if there is no prev. sibling, + return static_cast <KXE_TreeViewItem*> (parent()); // return this' parent (if there is any) +} + +KXE_TreeViewItem * KXE_TreeViewItem::nextItem() +{ + // checking for a child + QListViewItem * pTmp = firstChild(); + if (pTmp) + return static_cast <KXE_TreeViewItem*> (pTmp); + + // there is no child -> checking for the next sibling + pTmp = nextSibling(); + if (pTmp) + return static_cast <KXE_TreeViewItem*> (pTmp); + + // there is no next sibling -> checking for parents' next sibling(s) + QListViewItem * pParent = parent(); + while (pParent) + { + pTmp = pParent->nextSibling(); + if (pTmp) + return static_cast <KXE_TreeViewItem*> (pTmp); + pParent = pParent->parent(); + } + return 0; +} + +void KXE_TreeViewItem::expandSubTree( int iLevel ) +{ + setOpen(true); // expand this item + + if ( iLevel == 0 ) // return, if we are deep enough + return; + + // expand childs (recursive) + int iNewLevel = ( iLevel == -1 ) ? -1 : iLevel-1; + KXE_TreeViewItem * pChild = static_cast <KXE_TreeViewItem*> ( firstChild() ); + while ( pChild ) + { + pChild->expandSubTree(iNewLevel); + pChild = static_cast <KXE_TreeViewItem*> ( pChild->nextSibling() ); + } +} + +void KXE_TreeViewItem::collapseSubTree( int iLevel ) +{ + if ( iLevel < 0 ) + { + kdDebug() << "KXE_TreeViewItem::collapseSubTree: wrong level given (iLevel=" << iLevel << ")" << endl; + return; + } + + int iNewLevel; + if (iLevel==0) // collapse this item, + { // because we are deep enough + setOpen(false); + iNewLevel = 0; + } + else + iNewLevel = iLevel - 1; + + // collapsing in childs (recursive) + KXE_TreeViewItem * pChild = static_cast <KXE_TreeViewItem*> ( firstChild() ); + while ( pChild ) + { + pChild->collapseSubTree( iNewLevel ); + pChild = static_cast <KXE_TreeViewItem*> ( pChild->nextSibling() ); + } +} + +/** Test, if item in parameter is my direct or indirect child item */ +bool KXE_TreeViewItem::isMyChildren(const KXE_TreeViewItem *pTestItem) +{ + KXE_TreeViewItem* pChildXmlTreeItem = (KXE_TreeViewItem*) firstChild(); + while(pChildXmlTreeItem) + { if(pChildXmlTreeItem == pTestItem) + return true; + + // test child item childrens + if(pChildXmlTreeItem->isMyChildren(pTestItem)) + return true; + + pChildXmlTreeItem = (KXE_TreeViewItem*) pChildXmlTreeItem->nextSibling(); + } + return false; +} + + +void KXE_TreeViewItem::ensureChildItemsCreated() +{ + if ( ! m_bChildsCreated ) + { + QDomNode tmpNode = m_xmlNode.lastChild(); + + while ( ! tmpNode.isNull() ) + { + new KXE_TreeViewItem( tmpNode, this ); + tmpNode = tmpNode.previousSibling(); + } + + m_bChildsCreated = true; + } +} + + +void KXE_TreeViewItem::ensureGrandChildItemsCreated() +{ + if ( ! m_bGrandChildsCreated ) + { + // ensure, that all child items of this item are created + if ( ! m_bChildsCreated ) + ensureChildItemsCreated(); + + // Iterate over all children now and ensure their child items + // (this' grandchildrens) are created. + KXE_TreeViewItem * pChild = static_cast <KXE_TreeViewItem*> ( firstChild() ); + while ( pChild ) + { + pChild->ensureChildItemsCreated(); + pChild = static_cast <KXE_TreeViewItem*> ( pChild->nextSibling() ); + } + + m_bGrandChildsCreated = true; + } +} + +void KXE_TreeViewItem::startRename( int iCol ) +{ + // If the given column is set to be in-place renameable in this item's view, + // we can start renaming in-place. + // Remember: This function is only reached for items representing XML elements. + if ( (reinterpret_cast<KListView*> ( listView() ))->isRenameable( iCol ) ) + QListViewItem::startRename( iCol ); +} diff --git a/part/kxe_treeviewitem.h b/part/kxe_treeviewitem.h new file mode 100644 index 0000000..c24b99f --- /dev/null +++ b/part/kxe_treeviewitem.h @@ -0,0 +1,125 @@ +/*************************************************************************** + kxe_treeviewitem.h - description + ------------------- + begin : Wed Nov 21 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 KXE_TREEVIEWITEM_H +#define KXE_TREEVIEWITEM_H + +#include <qlistview.h> +#include <qpixmap.h> +#include <qdom.h> + +class KListView; + +/** + * This is a tree item, which represents one XML node (see @ref QDomNode and its childclasses). + * @short tree item + * @author The KXMLEditor Team + */ +class KXE_TreeViewItem : public QListViewItem +{ + public: + + KXE_TreeViewItem( const QDomNode & xmlNode, KListView * pParent, QListViewItem* pAfter=NULL); + KXE_TreeViewItem( const QDomNode & xmlNode, QListViewItem * pParent ); + KXE_TreeViewItem( const QDomNode & xmlNode, QListViewItem * pParent, QListViewItem * pAfter ); + ~KXE_TreeViewItem(); + + /** + * (Re)sets the texts of the columns of this listitem + * depending on type of corresponding XML node and + * element display mode, which is stored in the configuration + * (@ref KXETreeViewSettings::elemDisplMode). + */ + void setTexts(); + + /** Returns the corresponding XML node, e.g. the XML node represented by this tree item. */ + QDomNode * xmlNode() { return & m_xmlNode; } + + /** Returns true, if this tree item is bookmarked (false otherwise). */ + bool isBookmarked() const { return m_bBookmarked; } + + /** Changes this items bookmark status (see @ref KXE_TreeViewItem::m_bBookmarked) and returns the new one. */ + bool toggleBookmark(); + + /** Returns this items last child or a null pointer if there are no childs at all. */ + KXE_TreeViewItem * lastChild() const; + + /** Sets this items previous sibling. */ + void setPrevSibling( KXE_TreeViewItem * const pPrevSibling ) { m_pPrevSibling = pPrevSibling; } + + /** Returns this items previous sibling. */ + KXE_TreeViewItem * prevSibling() const { return m_pPrevSibling; } + + /** + * Does the same like @ref QListViewItem::itemAbove but the parent items doesn't need to be open. + * Returns this items previous siblings last grand child, if there is one. + * Otherwise it returns this items previous sibling or, + * if there are no sibling above, it returns this items parent or + * a null pointer (if there is no parent). + */ + KXE_TreeViewItem * prevItem(); + + /** + * Does the same like @ref QListViewItem::itemBelow but the parent items doesn't need to be open. + * Returns a pointer to the next item of this or a null pointer if this is the last item. + * This will be it's first child, + * if there are no childs, it will be the next sibling + * and if there are no siblings below, it will be this' parents next sibling ... + */ + KXE_TreeViewItem * nextItem(); + + /** Expands this items child tree up to the given level or expands the entire child tree, if iLevel == -1. */ + void expandSubTree( int iLevel = -1 ); + + /** Collapses this items child tree to the given level or collapses the entire child tree, if iLevel == 0. */ + void collapseSubTree( int iLevel = 0 ); + + /** Test, if item in parameter is my direct or indirect child item */ + bool isMyChildren(const KXE_TreeViewItem *); + + /** + * If the child items aren't created (initialized) yet + * (i.e. if m_bChildsCreated is false), it is done now. + */ + void ensureChildItemsCreated(); + /** + * If the grandchilds (child items of this item's childs) aren't created (initialized) + * yet (i.e. if m_bGrandChildsCreated is false), it is done now. + */ + void ensureGrandChildItemsCreated(); + + /** + * Starts in-place renaming, if the given column is set to be in-place + * renameable in the item's view + */ + virtual void startRename( int iCol ); + +protected: + + QDomNode m_xmlNode; + KXE_TreeViewItem * m_pPrevSibling; + bool m_bBookmarked; + bool m_bChildsCreated; + bool m_bGrandChildsCreated; + +private: + + void init(); + void initChilds(); +}; + +#endif diff --git a/part/kxe_viewattributes.cpp b/part/kxe_viewattributes.cpp new file mode 100644 index 0000000..ec6bffe --- /dev/null +++ b/part/kxe_viewattributes.cpp @@ -0,0 +1,157 @@ +/*************************************************************************** + kxe_viewattributes.cpp - description + ------------------- + begin : Thu Nov 22 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 "kxe_viewattributes.h" + +#include "kxeattributedialog.h" + +#include <kmessagebox.h> +#include <kdebug.h> +#include <klocale.h> + +KXE_ViewAttributes::KXE_ViewAttributes( QWidget * pParent, const char * pszName ) + : QTable( 0, 3, pParent, pszName ) +{ + horizontalHeader()->setLabel( 0, i18n("Namespace") ); + horizontalHeader()->setLabel( 1, i18n("Name") ); + horizontalHeader()->setLabel( 2, i18n("Value") ); + + setColumnReadOnly( 0, true ); + setColumnReadOnly( 1, true ); + setColumnReadOnly( 2, true ); + + connect( this, SIGNAL(valueChanged(int,int)), this, SLOT(slotItemRenamedInplace(int,int)) ); +} + +QDomAttr KXE_ViewAttributes::getSelectedAttribute() const +{ + if ( currentRow() == -1 ) + return QDomAttr(); + + if ( m_domElement.attributes().item(currentRow()).isAttr() ) + { + return m_domElement.attributes().item(currentRow()).toAttr(); + } + else + return QDomAttr(); +} + +void KXE_ViewAttributes::setReadWrite( bool fReadWrite ) +{ + setColumnReadOnly( 1, ! fReadWrite ); + setColumnReadOnly( 2, ! fReadWrite ); + + if ( fReadWrite ) + connect( this, SIGNAL(contextMenuRequested(int,int,const QPoint&)), this, SLOT(slotContextMenuRequested(int,int,const QPoint&)) ); + else + disconnect( this, SIGNAL(contextMenuRequested(int,int,const QPoint&)), this, SLOT(slotContextMenuRequested(int,int,const QPoint&)) ); +} + +void KXE_ViewAttributes::slotContextMenuRequested( int nRow, int nCol, const QPoint & pos ) +{ + nCol = nCol; + QString szMenuName = ( nRow == -1 ) ? "popupXmlAttributes" : "popupXmlAttribute"; + emit sigContextMenuRequested( szMenuName, pos ); +} + +void KXE_ViewAttributes::slotChange( const QDomElement & element ) +{ + m_domElement = element; + + uint iLength = m_domElement.attributes().length(); + setNumRows( iLength ); + + if ( iLength > 0 ) + { + for ( uint iRow = 0; iRow < iLength; iRow++ ) + { + QDomNode node = m_domElement.attributes().item(iRow); + if ( node.isAttr() ) + { + setText( iRow, 0, node.toAttr().namespaceURI() ); + setText( iRow, 1, node.toAttr().name() ); + setText( iRow, 2, node.toAttr().value() ); + adjustRow( iRow ); + } + else + kdError() << "KXE_ViewAttributes::slotChange: node is not an attribute (but should be)" << endl; + } + + adjustColumn(0); + adjustColumn(1); + adjustColumn(2); + } +} + +void KXE_ViewAttributes::slotItemRenamedInplace( int nRow, int nCol ) +{ + if ( nCol < 1) // only attributes names and values are changeable + { + kdError() << "KXMLEditor " << k_funcinfo << " column " << nCol << " should be unchangeable" << endl; + return; + } + + QDomNode node = m_domElement.attributes().item(nRow); + if ( node.isAttr() ) + { if (nCol == 1) + { + // check if name is OK + QString strMessage = KXEAttributeDialog::checkName(text(nRow,nCol)); + if(strMessage.length() > 0) + { + // restore old name + setText( nRow, 1, node.toAttr().name() ); // set old name + KMessageBox::sorry(this, strMessage); + return; + } + + // check, if new name not exists in attributes list + if(m_domElement.attributes().contains(text(nRow,nCol)) == false) + { + if ( node.toAttr().name() != text(nRow,nCol) ) // only if the name really was changed + { + emit sigAttributeNameChangedInplace(node.toAttr(), text(nRow,nCol) ); + } + } + else + { + KMessageBox::sorry(this, i18n("Attribute name already exists !")); + setText( nRow, 1, node.toAttr().name() ); // set old name + return; + } + } + else + { + if ( node.toAttr().value() != text(nRow,nCol) ) // only if the value really was changed + { + // check if value is OK + QString strMessage = KXEAttributeDialog::checkValue(text(nRow,nCol)); + if(strMessage.length() > 0) + { + // restore old value + setText( nRow, 2, node.toAttr().value() ); // set old value + KMessageBox::sorry(this, strMessage); + return; + } + + emit sigAttributeValueChangedInplace( node.toAttr(), text(nRow, nCol) ); + } + } + } + else + kdError() << "KXMLEditor " << k_funcinfo << " node is not an attribute (but should be)" << endl; +} diff --git a/part/kxe_viewattributes.h b/part/kxe_viewattributes.h new file mode 100644 index 0000000..c314c56 --- /dev/null +++ b/part/kxe_viewattributes.h @@ -0,0 +1,71 @@ +/*************************************************************************** + kxe_viewattributes.h - description + ------------------- + begin : Thu Nov 22 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 KXE_VIEWATTRIBUTES_H +#define KXE_VIEWATTRIBUTES_H + +#include <qtable.h> +#include <qdom.h> + +/** + * @author The KXMLEditor Team + */ +class KXE_ViewAttributes : public QTable +{ + Q_OBJECT + + public: + + KXE_ViewAttributes( QWidget * pParent = 0, const char * pszName = 0 ); + + /** Returns a pointer to the currently selected attribute or a null pointer. */ + QDomAttr getSelectedAttribute() const; + + /** Changes the behaviour of this view to readonly or readwrite. */ + void setReadWrite( bool fReadWrite ); + + public slots: + + /** Changes/Rebuilds the whole table according to the given element's attributes. */ + void slotChange( const QDomElement & element ); + + protected: + + /** the currently selected node */ + QDomElement m_domElement; + + protected slots: + + /** Called, when a context menu was requested (connected to @ref QTable::contextMenuRequested). */ + void slotContextMenuRequested( int nRow, int nCol, const QPoint & pos ); + + /** Called, when an item was changed via inplace editing. */ + void slotItemRenamedInplace( int nRow, int nCol ); + + signals: + + /** Emitted, when a context menu is requested */ + void sigContextMenuRequested( const QString & szMenuName, const QPoint & pos ); + + /** Emitted, when an attributes value was renamed via inplace editing. */ + void sigAttributeNameChangedInplace( const QDomAttr &, const QString ); + + /** Emitted, when an attributes value was renamed via inplace editing. */ + void sigAttributeValueChangedInplace( const QDomAttr &, const QString ); +}; + +#endif diff --git a/part/kxe_viewelement.cpp b/part/kxe_viewelement.cpp new file mode 100644 index 0000000..2bae53c --- /dev/null +++ b/part/kxe_viewelement.cpp @@ -0,0 +1,126 @@ +/*************************************************************************** + kxe_viewelement.cpp - description + ------------------- + begin : Mon Oct 15 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 "kxe_viewelement.h" +#include "kxe_viewattributes.h" +#include "kxesyntaxhighlighter.h" + +#include "kxmleditorfactory.h" +#include "kxeconfiguration.h" +#include "kxetextviewsettings.h" + +#include <kconfig.h> +#include <ktextedit.h> + +#include <qdom.h> +#include <qcolor.h> +#include <qpalette.h> + + +#include "qdom_add.h" + +#define CONFIG_SPLITTER_SIZES "View Element splitter sizes" + +KXE_ViewElement::KXE_ViewElement( QWidget * pParent, KConfig *pConfig, const char * pszName ) + : QSplitter( Qt::Vertical, pParent, pszName ) +{ + setOpaqueResize(true); + m_pConfig = pConfig; + m_pViewAttributes = new KXE_ViewAttributes( this, "table of element attributes"); + connect( m_pViewAttributes, SIGNAL(sigContextMenuRequested(const QString&,const QPoint&)), this, SIGNAL(sigContextMenuRequested(const QString&,const QPoint&)) ); + + connect( m_pViewAttributes, SIGNAL(sigAttributeNameChangedInplace(const QDomAttr&, const QString)), this, SIGNAL(sigAttributeNameChangedInplace(const QDomAttr&, const QString)) ); + connect( m_pViewAttributes, SIGNAL(sigAttributeValueChangedInplace(const QDomAttr&, const QString)), this, SIGNAL(sigAttributeValueChangedInplace(const QDomAttr&, const QString)) ); + + m_pViewPlainXML = new KTextEdit( this, "plain XML" ); + m_pViewPlainXML->setReadOnly(true); + m_pViewPlainXML->setTextFormat(KTextEdit::PlainText); + m_pViewPlainXML->setPaletteBackgroundColor(pParent->palette().active().base()); // Owerwrite read-only background color + m_pViewPlainXML->setWordWrap( QTextEdit::NoWrap ); + m_pSyntaxHighlighter = new KXESyntaxHighlighter(m_pViewPlainXML); + + // configuring splitter sizes + if (m_pConfig) + { + QValueList<int> list = m_pConfig->readIntListEntry(CONFIG_SPLITTER_SIZES); + if (!list.isEmpty()) + setSizes(list); + } + + // Apply current configuration + slotTextViewSettingsChanged(); + // and make sure to be informed about its changes. + connect( KXMLEditorFactory::configuration()->textview(), SIGNAL(sigChanged()), this, SLOT(slotTextViewSettingsChanged()) ); +} + +KXE_ViewElement::~KXE_ViewElement() +{ + // saving splitter sizes + if (m_pConfig) + m_pConfig->writeEntry( CONFIG_SPLITTER_SIZES, sizes() ); + + delete m_pSyntaxHighlighter; +} + +QDomAttr KXE_ViewElement::getSelectedAttribute() const +{ + return m_pViewAttributes->getSelectedAttribute(); +} + +void KXE_ViewElement::setReadWrite( bool fReadWrite ) +{ + m_pViewAttributes->setReadWrite(fReadWrite); +} + +void KXE_ViewElement::slotChange( const QDomElement & element ) +{ + // change attribute view + m_pViewAttributes->slotChange(element); + + int iIndent = KXMLEditorFactory::configuration()->textview()->indentSteps(); + + // change plain XML view + m_pViewPlainXML->setText( domTool_save(element, iIndent) ); +} + +////////////////////////////////////////////////////////////// +// configuration slots +////////////////////////////////////////////////////////////// + +void KXE_ViewElement::slotTextViewSettingsChanged() +{ + m_pSyntaxHighlighter->setColorDefaultText( KXMLEditorFactory::configuration()->textview()->colorDfltText() ); + m_pSyntaxHighlighter->setColorElementNames( KXMLEditorFactory::configuration()->textview()->colorElemNames() ); + m_pSyntaxHighlighter->setColorAttributeNames( KXMLEditorFactory::configuration()->textview()->colorAttrNames() ); + m_pSyntaxHighlighter->setColorAttributeValues( KXMLEditorFactory::configuration()->textview()->colorAttrValues() ); + m_pSyntaxHighlighter->setColorXmlSyntaxChars( KXMLEditorFactory::configuration()->textview()->colorSyntaxChars() ); + m_pSyntaxHighlighter->setColorComments( KXMLEditorFactory::configuration()->textview()->colorComments() ); + m_pSyntaxHighlighter->setColorSyntaxError( KXMLEditorFactory::configuration()->textview()->colorErrors() ); + + if(KXMLEditorFactory::configuration()->textview()->isWrapOn()) + { + m_pViewPlainXML->setHScrollBarMode(QScrollView::AlwaysOff); + m_pViewPlainXML->setWordWrap(QTextEdit::WidgetWidth); + } + else + { + m_pViewPlainXML->setHScrollBarMode(QScrollView::Auto); + m_pViewPlainXML->setWordWrap(QTextEdit::NoWrap); + } + + m_pSyntaxHighlighter->rehighlight(); +} diff --git a/part/kxe_viewelement.h b/part/kxe_viewelement.h new file mode 100644 index 0000000..bac7669 --- /dev/null +++ b/part/kxe_viewelement.h @@ -0,0 +1,94 @@ +/*************************************************************************** + kxe_viewelement.h - description + ------------------- + begin : Mon Oct 15 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 KXE_VIEWELEMENT_H +#define KXE_VIEWELEMENT_H + +#include <qsplitter.h> + +#include <qdom.h> + +// forward declarations +class KXE_ViewAttributes; +class KTextEdit; +class KConfig; +class KXESyntaxHighlighter; + + +/** + * This widget shows a table of XML elements attributes + * and plain XML text of this element and its children. + * + * @short Widget for XML elements. + */ +class KXE_ViewElement : public QSplitter +{ + Q_OBJECT + + public: + + KXE_ViewElement( QWidget * pParent, KConfig *pConfig, const char * pszName = 0 ); + ~KXE_ViewElement(); + + /** Returns a pointer to the currently selected attribute or a null pointer. */ + QDomAttr getSelectedAttribute() const; + + /** Changes the behaviour of this view to readonly or readwrite. */ + void setReadWrite( bool fReadWrite ); + + public slots: + + /** Changes/Rebuilds the whole widget according to the given element. */ + void slotChange( const QDomElement & ); + + /** + * Changes syntax highlighting colors. + */ + void slotTextViewSettingsChanged(); + + protected: + + /** table widget to display XML attributes */ + KXE_ViewAttributes * m_pViewAttributes; + /** edit widget for plain XML */ + KTextEdit * m_pViewPlainXML; + + /** configuration used to store splitter sizes */ + KConfig *m_pConfig; + + /** Syntax highlighter for m_pViewPlainXML */ + KXESyntaxHighlighter *m_pSyntaxHighlighter; + + signals: + + /** Emitted, when a context menu is requested (see @ref KXE_ViewAttributes::sigContextMenuRequested) */ + void sigContextMenuRequested( const QString & szMenuName, const QPoint & pos ); + + /** + * Emitted, when an attributes name was renamed via inplace editing + * (see @ref KXE_ViewAttributes::sigAttributeChangedInplace). + */ + void sigAttributeNameChangedInplace( const QDomAttr &, const QString ); + + /** + * Emitted, when an attributes value was renamed via inplace editing + * (see @ref KXE_ViewAttributes::sigAttributeChangedInplace). + */ + void sigAttributeValueChangedInplace( const QDomAttr &, const QString ); +}; + +#endif diff --git a/part/kxearchiveextssettings.cpp b/part/kxearchiveextssettings.cpp new file mode 100644 index 0000000..ec800c6 --- /dev/null +++ b/part/kxearchiveextssettings.cpp @@ -0,0 +1,153 @@ +/*************************************************************************** + kxearchiveextssettings.cpp + -------------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 "kxearchiveextssettings.h" +#include "kxearchiveextssettingspage.h" + +#include <klocale.h> +#include <kconfig.h> + +#include <qframe.h> +#include <qlistbox.h> +#include <qlineedit.h> +#include <qpushbutton.h> + +#define CONF_ENTRY_NAME_EXTS_TARGZ "Extensions" + +KXEArchiveExtsSettings::KXEArchiveExtsSettings( QObject * pParent, const char * pszName ) + : KXESettings( "TarGz Extensions", pParent, pszName ), + m_pDialogPage(0) +{ +} + + +void KXEArchiveExtsSettings::write( KConfig * pConfig ) const +{ + pConfig->writeEntry( CONF_ENTRY_NAME_EXTS_TARGZ, m_lstExtensions ); +} + + +void KXEArchiveExtsSettings::read( const KConfig * pConfig ) +{ + m_lstExtensions = pConfig->readListEntry( CONF_ENTRY_NAME_EXTS_TARGZ ); +} + +QString KXEArchiveExtsSettings::dialogPageName() const +{ + return i18n( "Archive Extensions" ); +} + +QString KXEArchiveExtsSettings::dialogPageHeader() const +{ + return i18n( "Specify Archive Extensions" ); +} + +QString KXEArchiveExtsSettings::dialogPageIcon() const +{ + return "filetypes"; +} + +QWidget * KXEArchiveExtsSettings::dialogPage( QFrame * pParent ) +{ + if ( ! m_pDialogPage ) + { + // create the page if necessary + m_pDialogPage = new KXEArchiveExtsSettingsPage( pParent, "archive extensions config.dialog page" ); + + // and fill its widgets with the corresponding values + updatePage(); + + connect( m_pDialogPage->m_pExtensions, SIGNAL(highlighted(const QString&)), this, SLOT(slotPageEditExtension(const QString&)) ); + connect( m_pDialogPage->m_pBtnNew, SIGNAL(clicked()), this, SLOT(slotPageAddExtension()) ); + connect( m_pDialogPage->m_pBtnDelete, SIGNAL(clicked()), this, SLOT(slotPageDeleteExtension()) ); + connect( m_pDialogPage->m_pExtension, SIGNAL(textChanged(const QString&)), this, SLOT(slotPageUpdateExtension(const QString&)) ); + + connect( m_pDialogPage->m_pBtnNew, SIGNAL(clicked()), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pBtnDelete, SIGNAL(clicked()), this, SIGNAL(sigDialogPageChanged()) ); + } + + return m_pDialogPage; +} + + +void KXEArchiveExtsSettings::setFromPage() +{ + if ( m_pDialogPage ) + { + m_lstExtensions.clear(); + QListBoxItem * pTmpItem = m_pDialogPage->m_pExtensions->firstItem(); + while ( pTmpItem ) + { + m_lstExtensions << pTmpItem->text(); + pTmpItem = pTmpItem->next(); + } + } +} + +void KXEArchiveExtsSettings::updatePage() const +{ + if ( m_pDialogPage ) + { + m_pDialogPage->m_pExtensions->clear(); + m_pDialogPage->m_pExtensions->insertStringList( m_lstExtensions ); + m_pDialogPage->m_pExtension->setDisabled( true ); + } +} + + +////////////////////////////////////////////////////////////////////// +// additional slots for the corresponding configuration dialog page // +////////////////////////////////////////////////////////////////////// + +void KXEArchiveExtsSettings::slotPageEditExtension( const QString & strText ) +{ + m_pDialogPage->m_pExtension->setText( strText ); + m_pDialogPage->m_pExtension->setEnabled( true ); + m_pDialogPage->m_pExtension->setFocus(); +} + +void KXEArchiveExtsSettings::slotPageAddExtension() +{ + m_pDialogPage->m_pExtensions->insertItem( "zip", 0 ); + m_pDialogPage->m_pExtensions->setCurrentItem( 0 ); + m_pDialogPage->m_pExtension->selectAll(); + m_pDialogPage->m_pExtension->setFocus(); + m_pDialogPage->m_pExtension->setEnabled( true ); +} + +void KXEArchiveExtsSettings::slotPageDeleteExtension() +{ + m_pDialogPage->m_pExtensions->removeItem( m_pDialogPage->m_pExtensions->currentItem() ); + + if ( m_pDialogPage->m_pExtensions->count() == 0 ) + { + m_pDialogPage->m_pExtension->clear(); + m_pDialogPage->m_pExtension->setDisabled( true ); + } + else + m_pDialogPage->m_pExtensions->setSelected( m_pDialogPage->m_pExtensions->currentItem(), true ); +} + +void KXEArchiveExtsSettings::slotPageUpdateExtension( const QString & strText ) +{ + if ( ( m_pDialogPage->m_pExtensions->count() > 0 ) && + ( m_pDialogPage->m_pExtensions->currentText() != m_pDialogPage->m_pExtension->text() ) ) + { + m_pDialogPage->m_pExtensions->changeItem( strText, m_pDialogPage->m_pExtensions->currentItem() ); + emit sigDialogPageChanged(); + } +} diff --git a/part/kxearchiveextssettings.h b/part/kxearchiveextssettings.h new file mode 100644 index 0000000..ad2f212 --- /dev/null +++ b/part/kxearchiveextssettings.h @@ -0,0 +1,113 @@ +/*************************************************************************** + kxearchiveextssettings.h + ------------------ + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 KXEARCHIVEEXTSSETTINGS_H +#define KXEARCHIVEEXTSSETTINGS_H + +#include "kxesettings.h" + +#include <qstringlist.h> + +class KXEArchiveExtsSettingsPage; + +/** + * This class represents the group of configuration settings for the + * archive extensions. + * + * @author Olaf Hartig + */ +class KXEArchiveExtsSettings : public KXESettings +{ + Q_OBJECT + + public: + + KXEArchiveExtsSettings( QObject * pParent = 0, const char * pszName = 0 ); + + // The following function(s) can be used to access this object's settings. + const QStringList & extensions() const { return m_lstExtensions; } + + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageName() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageHeader() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageIcon() const; + /** + * Derived from @ref KXESettings + */ + virtual QWidget * dialogPage( QFrame * pParent ); + + protected: + + /** + * Derived from @ref KXESettings + */ + virtual void write( KConfig * ) const; + /** + * Derived from @ref KXESettings + */ + virtual void read( const KConfig * ); + /** + * Derived from @ref KXESettings + */ + virtual void setFromPage(); + /** + * Derived from @ref KXESettings + */ + virtual void updatePage() const; + + // the settings itself + QStringList m_lstExtensions; + + /** + * the corresponding configuration dialog page + * It is created on demand by @ref dialogPage. + */ + KXEArchiveExtsSettingsPage * m_pDialogPage; + + protected slots: + + // The following slots contain additional functionality + // for the corresponding configuration dialog page. + + /** + * Copies the selected item's extension to the editline. + */ + void slotPageEditExtension( const QString & ); + /** + * Creates a new (empty) item/ extension in the listbox and selects it. + */ + void slotPageAddExtension(); + /** + * Removes the currently selected item / extension from the listbox. + */ + void slotPageDeleteExtension(); + /** + * Copies the lineedit's current text to the currently selected item. + */ + void slotPageUpdateExtension( const QString & ); + +}; + +#endif diff --git a/part/kxearchiveextssettingspage.ui b/part/kxearchiveextssettingspage.ui new file mode 100644 index 0000000..0936850 --- /dev/null +++ b/part/kxearchiveextssettingspage.ui @@ -0,0 +1,175 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXEArchiveExtsSettingsPage</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KXEArchiveExtsSettingsPage</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>293</width> + <height>187</height> + </rect> + </property> + <property name="caption"> + <string>Archive Exts Settings Page</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>m_pLblExtensions</cstring> + </property> + <property name="text"> + <string>Extensions of archive &files:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pExtensions</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Extensions of archive files</b> +<br> +This list contains the known extensions for archive files.<br> +You can choose one to edit or remove it with the dialog widgets below.</string> + </property> + </widget> + <widget class="QListBox" row="1" column="0"> + <property name="name"> + <cstring>m_pExtensions</cstring> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>80</height> + </size> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Extensions of archive files</b> +<br> +This list contains the known extensions for archive files.</string> + </property> + </widget> + <widget class="QLayoutWidget" row="2" column="0"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>m_pLblExtension</cstring> + </property> + <property name="text"> + <string>&Extension:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pExtension</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Extension</b> +<br> +Change the selected extension here.</string> + </property> + </widget> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>m_pExtension</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Extension</b> +<br> +Change the selected extension here.</string> + </property> + </widget> + <spacer row="1" column="0"> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>71</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget" row="1" column="1"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnNew</cstring> + </property> + <property name="text"> + <string>&New</string> + </property> + <property name="accel"> + <string>Alt+N</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>New</b> +<br> +You can create a new item for another known extension in the list above.</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnDelete</cstring> + </property> + <property name="text"> + <string>&Delete</string> + </property> + <property name="accel"> + <string>Alt+D</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Delete</b> +<br> +You can delete the selected extension from the list above.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>41</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + </grid> + </widget> + </grid> +</widget> +<slots> + <slot>slotUpdateExtension( const QString & )</slot> + <slot>slotDeleteExtension()</slot> + <slot>slotAddExtension()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxeattachdialogbase.ui b/part/kxeattachdialogbase.ui new file mode 100644 index 0000000..447ac9f --- /dev/null +++ b/part/kxeattachdialogbase.ui @@ -0,0 +1,144 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXEAttachDialogBase</class> +<widget class="QDialog"> + <property name="name"> + <cstring>KXEAttachDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>319</width> + <height>105</height> + </rect> + </property> + <property name="caption"> + <string>Attach to XML</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>Label</cstring> + </property> + <property name="text"> + <string>attachment URI:</string> + </property> + </widget> + <widget class="KURLRequester"> + <property name="name"> + <cstring>attachURI</cstring> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonHelp</cstring> + </property> + <property name="text"> + <string>&Help</string> + </property> + <property name="accel"> + <string>F1</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string></string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>buttonOk</sender> + <signal>clicked()</signal> + <receiver>KXEAttachDialogBase</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>KXEAttachDialogBase</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>attachURI</tabstop> + <tabstop>buttonOk</tabstop> + <tabstop>buttonCancel</tabstop> + <tabstop>buttonHelp</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kurlrequester.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> +</includehints> +</UI> diff --git a/part/kxeattributedialog.cpp b/part/kxeattributedialog.cpp new file mode 100644 index 0000000..d64b796 --- /dev/null +++ b/part/kxeattributedialog.cpp @@ -0,0 +1,179 @@ +/*************************************************************************** + kxeattributedialog.cpp - description + ---------------------- + begin : Fre Jul 12 2002 + copyright : (C) 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 "kxeattributedialog.h" + +#include <klineedit.h> +#include <kdebug.h> +#include <klocale.h> + +#include <qpushbutton.h> +#include <qlabel.h> + +KXEAttributeDialog::KXEAttributeDialog( QWidget * pParent, const char * pszName, bool fModal, WFlags fl ) + : KXEAttributeDialogBase( pParent, pszName, fModal, fl ) +{ + connect( m_pEditNamespace, SIGNAL(textChanged(const QString &)), this, SLOT(slotNamespaceChanged(const QString &)) ); + connect( m_pEditQName, SIGNAL(textChanged(const QString &)), this, SLOT(slotNameChanged(const QString &)) ); + connect( m_pEditValue, SIGNAL(textChanged(const QString &)), this, SLOT(slotValueChanged(const QString &)) ); +} + +void KXEAttributeDialog::clearDialog() +{ + m_pEditNamespace->clear(); + m_pEditQName->clear(); + m_pEditValue->clear(); +} + +int KXEAttributeDialog::exec() +{ + clearDialog(); + + m_pBtnOK->setEnabled(false); + + m_pEditQName->setFocus(); + m_pBtnOK->setDefault(true); + + int iReturn = KXEAttributeDialogBase::exec(); + if ( iReturn == Accepted ) + { + m_strNamespace = m_pEditNamespace->text(); + m_strQName = m_pEditQName->text(); + m_strValue = m_pEditValue->text(); + } + + return iReturn; +} + +void KXEAttributeDialog::slotNameChanged(const QString & strNewName) +{ + QString strMessage = checkName(strNewName); + if(strMessage.isEmpty()) + { + strMessage = checkNamespace(m_pEditNamespace->text()); + if(strMessage.isEmpty()) + strMessage = checkValue(m_pEditValue->text()); + } + + m_pTextLabelMessage->setText(strMessage); + + if ( strNewName.isEmpty() || (strMessage.length() > 0) ) + m_pBtnOK->setEnabled(false); + else + m_pBtnOK->setEnabled(true); +} + +void KXEAttributeDialog::slotValueChanged(const QString & strNewValue) +{ + QString strMessage = checkName(m_pEditQName->text()); + if(strMessage.isEmpty()) + { + strMessage = checkNamespace(m_pEditNamespace->text()); + if(strMessage.isEmpty()) + strMessage = checkValue(strNewValue); + } + + m_pTextLabelMessage->setText(strMessage); + + if ( m_pEditQName->text().isEmpty() || (strMessage.length() > 0) ) + m_pBtnOK->setEnabled(false); + else + m_pBtnOK->setEnabled(true); +} + +void KXEAttributeDialog::slotNamespaceChanged(const QString & strNewNamespace) +{ + QString strMessage = checkName(m_pEditQName->text()); + if(strMessage.isEmpty()) + { + strMessage = checkNamespace(strNewNamespace); + if(strMessage.isEmpty()) + strMessage = checkValue(m_pEditValue->text()); + } + + m_pTextLabelMessage->setText(strMessage); + + if ( m_pEditQName->text().isEmpty() || (strMessage.length() > 0) ) + m_pBtnOK->setEnabled(false); + else + m_pBtnOK->setEnabled(true); +} + +// Check, if XML attribute name is OK +QString KXEAttributeDialog::checkNamespace(const QString strAtttributeName) +{ + if(strAtttributeName.length() == 0) + return ""; + + // test for space + if(strAtttributeName.find(' ') >= 0) + return i18n("Atttribute namespace cannot contain space !"); + + // Forbidden characters + QString strForbiddenChars("<>\"'"); + for(unsigned int i = 0; i < strForbiddenChars.length(); i++) + { + QChar ch = strForbiddenChars[i]; + + if(strAtttributeName.find(ch) >= 0) + return i18n("Atttribute namespace cannot contain character: %1 !").arg(ch); + } + + return ""; +} + +// Check, if XML attribute name is OK +QString KXEAttributeDialog::checkName(const QString strAtttributeName) +{ + if(strAtttributeName.length() == 0) + return ""; + + // test for space + if(strAtttributeName.find(' ') >= 0) + return i18n("Atttribute name cannot contain space !"); + + // Forbidden characters + QString strForbiddenChars("&@#$%^()%+?=:<>;\"'*"); + for(unsigned int i = 0; i < strForbiddenChars.length(); i++) + { + QChar ch = strForbiddenChars[i]; + + if(strAtttributeName.find(ch) >= 0) + return i18n("Atttribute name cannot contain character: %1 !").arg(ch); + } + + return ""; +} + +// Check, if XML attribute value is OK +QString KXEAttributeDialog::checkValue(const QString strData) +{ + if(strData.length() == 0) + return ""; + + // Forbidden characters + QString strForbiddenChars("<>\""); + for(unsigned int i = 0; i < strForbiddenChars.length(); i++) + { + QChar ch = strForbiddenChars[i]; + + if(strData.find(ch) >= 0) + return i18n("Attribute value cannot contain character: %1 !").arg(ch); + } + + return ""; +} diff --git a/part/kxeattributedialog.h b/part/kxeattributedialog.h new file mode 100644 index 0000000..e2019b9 --- /dev/null +++ b/part/kxeattributedialog.h @@ -0,0 +1,82 @@ +/*************************************************************************** + kxeattributedialog.h - description + -------------------- + begin : Fre Jul 12 2002 + copyright : (C) 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 KXEATTRIBUTEDIALOG_H +#define KXEATTRIBUTEDIALOG_H + +#include "kxeattributedialogbase.h" + +#include <qdom.h> + +class KXEAttributeDialog : public KXEAttributeDialogBase +{ + Q_OBJECT + + public: + KXEAttributeDialog( QWidget * pParent = 0, const char * pszName = 0, bool fModal = true, WFlags fl = 0 ); + + const QString attributeNamespace() const { return m_strNamespace; } + const QString QName() const { return m_strQName; } + const QString Value() const { return m_strValue; } + + /** + * To be used for adding an attribute to new XML element. + * + * @return see @ref QDialog::exec + */ + int exec( ); + + /** + * Clears the dialogs widgets. + */ + void clearDialog(); + + // Check, if XML attribute name is OK + static QString checkName(const QString); + + // Check, if XML attribute value is OK + static QString checkValue(const QString); + + // Check, if XML attribute namespace is OK + static QString checkNamespace(const QString); + + protected slots: + /** + * Called, when user change attribute name. + * Disables the OK button, if user input is wrong or incomplete. + */ + void slotNameChanged(const QString &); + + /** + * Called, when user change attribute value. + * Disables the OK button, if user input is wrong or incomplete. + */ + void slotValueChanged(const QString &); + + /** + * Called, when user change attribute namespace. + * Disables the OK button, if user input is wrong or incomplete. + */ + void slotNamespaceChanged(const QString &); + + protected: + QString m_strNamespace; + QString m_strQName; + QString m_strValue; +}; + +#endif diff --git a/part/kxeattributedialogbase.ui b/part/kxeattributedialogbase.ui new file mode 100644 index 0000000..d03b8eb --- /dev/null +++ b/part/kxeattributedialogbase.ui @@ -0,0 +1,263 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXEAttributeDialogBase</class> +<widget class="QDialog"> + <property name="name"> + <cstring>KXEAttributeDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>339</width> + <height>262</height> + </rect> + </property> + <property name="caption"> + <string>XML Attribute</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer row="1" column="1"> + <property name="name"> + <cstring>Spacer3</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <spacer row="5" column="1"> + <property name="name"> + <cstring>Spacer4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <spacer row="3" column="1"> + <property name="name"> + <cstring>Spacer4_2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLineEdit" row="1" column="0"> + <property name="name"> + <cstring>m_pEditNamespace</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Namespace URI</b> +<br/> +Enter the namespace URI for this attribute here.</string> + </property> + </widget> + <widget class="QLineEdit" row="5" column="0"> + <property name="name"> + <cstring>m_pEditValue</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Value</b> +<br/> +Enter the attribute's value here.</string> + </property> + </widget> + <widget class="QLineEdit" row="3" column="0"> + <property name="name"> + <cstring>m_pEditQName</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Qualified Name</b> +<br/> +Enter a qualified name for the attribute here.</string> + </property> + </widget> + <widget class="QLayoutWidget" row="7" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnOK</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string>Alt+O</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string>Alt+C</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>m_pLblValue</cstring> + </property> + <property name="text"> + <string>&Value:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pEditValue</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Value</b> +<br/> +Enter the attribute's value here.</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>m_pLblQName</cstring> + </property> + <property name="text"> + <string>Qualified &Name:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pEditQName</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Qualified Name</b> +<br/> +Enter a qualified name for the attribute here.</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>m_pLblNamespace</cstring> + </property> + <property name="text"> + <string>Namespace &URI:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pEditNamespace</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Namespace URI</b> +<br/> +Enter the namespace URI for this attribute here.</string> + </property> + </widget> + <widget class="QLabel" row="6" column="0"> + <property name="name"> + <cstring>m_pTextLabelMessage</cstring> + </property> + <property name="paletteForegroundColor"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="textFormat"> + <enum>PlainText</enum> + </property> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>m_pBtnOK</sender> + <signal>clicked()</signal> + <receiver>KXEAttributeDialogBase</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>m_pBtnCancel</sender> + <signal>clicked()</signal> + <receiver>KXEAttributeDialogBase</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>m_pEditQName</tabstop> + <tabstop>m_pEditValue</tabstop> + <tabstop>m_pBtnOK</tabstop> + <tabstop>m_pBtnCancel</tabstop> + <tabstop>m_pEditNamespace</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxechardatadialog.cpp b/part/kxechardatadialog.cpp new file mode 100644 index 0000000..fb74ad4 --- /dev/null +++ b/part/kxechardatadialog.cpp @@ -0,0 +1,119 @@ +/*************************************************************************** + kxechardatadialog.cpp - description + --------------------- + begin : Don Apr 25 2002 + copyright : (C) 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 "kxechardatadialog.h" + +#include <qlabel.h> +#include <qcombobox.h> +#include <qpushbutton.h> +#include <qtextedit.h> + +#include <kdebug.h> +#include <klocale.h> + +KXECharDataDialog::KXECharDataDialog( QWidget * pParent, const char * pszName, bool fModal, WFlags fl ) + : KXECharDataDialogBase( pParent, pszName, fModal, fl ) +{ + connect( m_pEditData, SIGNAL(textChanged()), this, SLOT(slotDataChanged()) ); +} + +void KXECharDataDialog::clearDialog() +{ + m_pEditData->clear(); +} + +int KXECharDataDialog::exec( bool bEditExisting ) +{ + if(bEditExisting) + { + m_pComboInsert->hide(); + m_pComboInsert->setDisabled(true); + m_pLblInsert->hide(); + m_pLblInsert->setDisabled(true); + +// m_pComboType->setDisabled(true); + + m_pEditData->setText( m_strContents ); +// m_pComboType->setCurrentItem(m_eCharDataKind); + } + else + { +// m_pComboType->setEnabled(true); + clearDialog(); + } + + int iReturn = exec(); + if ( iReturn == Accepted ) + { + m_strContents = m_pEditData->text(); + m_bAtTop = ( m_pComboInsert->currentItem() == 0 ); +// m_eCharDataKind = (CharDataKind) m_pComboType->currentItem(); + } + + return iReturn; +} + +int KXECharDataDialog::exec() +{ + if ( m_pEditData->text().isEmpty() ) + m_pBtnOK->setEnabled(false); + else + m_pBtnOK->setEnabled(true); + + m_pEditData->setFocus(); + m_pBtnOK->setDefault(true); + + return KXECharDataDialogBase::exec(); +} + +void KXECharDataDialog::slotDataChanged() +{ + QString strMessage = checkContents(m_pEditData->text()); + + m_pTextLabelMessage->setText(strMessage); + + if ( m_pEditData->text().isEmpty() || (strMessage.length() > 0)) + m_pBtnOK->setEnabled(false); + else + m_pBtnOK->setEnabled(true); +} + +// Check, if XML chardata contents is OK +QString KXECharDataDialog::checkContents(const QString strData) +{ + if(strData.length() == 0) + return ""; + + // Forbidden characters + /*QString strForbiddenChars("<>"); + for(unsigned int i = 0; i < strForbiddenChars.length(); i++) + { + QChar ch = strForbiddenChars[i]; + + if(strData.find(ch) >= 0) + return i18n("Contents cannot contain character: %1 !").arg(ch); + } + + L.V. Removed this check, bacause QDomCharacterData.setData() escapec special + charactesr and data() unescapes it back to original string + + */ + + return ""; +} + + diff --git a/part/kxechardatadialog.h b/part/kxechardatadialog.h new file mode 100644 index 0000000..7e1507b --- /dev/null +++ b/part/kxechardatadialog.h @@ -0,0 +1,83 @@ +/*************************************************************************** + kxechardatadialog.h - description + ------------------- + begin : Don Apr 25 2002 + copyright : (C) 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 KXECHARDATADIALOG_H +#define KXECHARDATADIALOG_H + +#include "kxechardatadialogbase.h" + +enum CharDataKind + { + CharDataTextNode = 0, + CharDataCDATASection, + CharDataComment + }; + +class KXECharDataDialog : public KXECharDataDialogBase +{ + Q_OBJECT + + public: + KXECharDataDialog( QWidget * pParent = 0, const char * pszName = 0, bool fModal = true, WFlags fl = 0 ); + +// const CharDataKind charDataKind() const { return m_eCharDataKind; } + const bool atTop() const { return m_bAtTop; } + const QString contents() const { return m_strContents; } + + void setContents(const QString strContents) { m_strContents = strContents; } +// void setCharDataKind(const CharDataKind eCharDataKind) { m_eCharDataKind = eCharDataKind; } + + public: + + /** + * To be used for inserting the given XML character data as child + * of the given parent element. + * + * @return see @ref QDialog::exec + */ + int exec( bool ); + + /** + * Clears the dialogs widgets. + */ + void clearDialog(); + + // check contents + static QString checkContents(const QString); + + protected: + /** + * Don't use this function directly, it's for internal use only. + * Use one of the other @ref DlgXMLCharData::exec functions instead. + */ + int exec(); + + protected slots: + /** + * Called, when the data in the text edit @ref DlgXMLCharDataBase::m_pEditData + * is changed. + * Disables the OK button, if the given string is empty. + */ + void slotDataChanged(); + + protected: + //CharDataKind m_eCharDataKind; + bool m_bAtTop; + QString m_strContents; +}; + +#endif diff --git a/part/kxechardatadialogbase.ui b/part/kxechardatadialogbase.ui new file mode 100644 index 0000000..7f8b874 --- /dev/null +++ b/part/kxechardatadialogbase.ui @@ -0,0 +1,213 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXECharDataDialogBase</class> +<widget class="QDialog"> + <property name="name"> + <cstring>KXECharDataDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>389</width> + <height>289</height> + </rect> + </property> + <property name="caption"> + <string>XML Character Data</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>Layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblInsert</cstring> + </property> + <property name="text"> + <string>&Insert:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pComboInsert</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Insert</b> +<br/> +Choose, where to place this XML character data in the XML elements list of childnodes.</string> + </property> + </widget> + <widget class="QComboBox"> + <item> + <property name="text"> + <string>at bottom</string> + </property> + </item> + <item> + <property name="text"> + <string>at top</string> + </property> + </item> + <property name="name"> + <cstring>m_pComboInsert</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Insert</b> +<br/> +Choose, where to place this XML character data in the XML elements list of childnodes.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer6</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QTextEdit" row="1" column="0"> + <property name="name"> + <cstring>m_pEditData</cstring> + </property> + <property name="textFormat"> + <enum>PlainText</enum> + </property> + <property name="wordWrap"> + <enum>NoWrap</enum> + </property> + <property name="whatsThis" stdset="0"> + <string>You can edit the XML character data in this editor.</string> + </property> + </widget> + <widget class="QLayoutWidget" row="3" column="0"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnOK</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string>Alt+O</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>m_pTextLabelMessage</cstring> + </property> + <property name="paletteForegroundColor"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="textFormat"> + <enum>PlainText</enum> + </property> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>m_pBtnOK</sender> + <signal>clicked()</signal> + <receiver>KXECharDataDialogBase</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>m_pBtnCancel</sender> + <signal>clicked()</signal> + <receiver>KXECharDataDialogBase</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>m_pEditData</tabstop> + <tabstop>m_pBtnOK</tabstop> + <tabstop>m_pBtnCancel</tabstop> + <tabstop>m_pComboInsert</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxechoosestringdialog.cpp b/part/kxechoosestringdialog.cpp new file mode 100644 index 0000000..d36ed68 --- /dev/null +++ b/part/kxechoosestringdialog.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** + kxechoosestringdialog.cpp - description + ------------------------- + begin : Fri Jul 20 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 "kxechoosestringdialog.h" + +#include <qpushbutton.h> +#include <qcombobox.h> +#include <qlabel.h> + +KXEChooseStringDialog::KXEChooseStringDialog(QWidget *parent, + const char *name, + const char *szCaption, + const char *szPrompt) + : KXEChooseStringDialogBase(parent, name, true) +{ + m_pComboBox->setEditable(true); + m_pComboBox->setFocus(); + m_pPushButtonOk->setDefault(true); + setCaption(szCaption); + m_pTextLabel->setText(szPrompt); +} + +/** Called, when user press OK button */ +void KXEChooseStringDialog::slotOk() +{ + m_strChoosedText = m_pComboBox->currentText(); + accept(); +} diff --git a/part/kxechoosestringdialog.h b/part/kxechoosestringdialog.h new file mode 100644 index 0000000..2065e3a --- /dev/null +++ b/part/kxechoosestringdialog.h @@ -0,0 +1,44 @@ +/*************************************************************************** + kxechoosestringdialog.h - description + ----------------------- + begin : Fri Jul 20 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 KXECHOOSESTRINGDIALOG_H +#define KXECHOOSESTRINGDIALOG_H + +#include "kxechoosestringdialogbase.h" + +#include <qwidget.h> + +/**Dialog with combobox that allow enter +or select any string + *@author Lumir Vanek + */ + +class KXEChooseStringDialog : public KXEChooseStringDialogBase +{ + Q_OBJECT +public: + KXEChooseStringDialog(QWidget *, const char *, const char *, const char *); + +protected slots: // Protected slots + /** Called, when user press OK button */ + void slotOk(); +public: // Public attributes + /** Contain text choosed by user */ + QString m_strChoosedText; +}; + +#endif diff --git a/part/kxechoosestringdialogbase.ui b/part/kxechoosestringdialogbase.ui new file mode 100644 index 0000000..5fb8079 --- /dev/null +++ b/part/kxechoosestringdialogbase.ui @@ -0,0 +1,143 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXEChooseStringDialogBase</class> +<comment>Dialog with combobox that allow enter +or select any string</comment> +<author>Lumir Vanek</author> +<widget class="QDialog"> + <property name="name"> + <cstring>KXEChooseStringDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>228</width> + <height>137</height> + </rect> + </property> + <property name="caption"> + <string>Choose string</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QComboBox" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_pComboBox</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Enter string<b/> +<br/> +Enter or choose string, that you want.</string> + </property> + </widget> + <widget class="QLayoutWidget" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Spacer4</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pPushButtonOk</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pPushButtonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>m_pTextLabel</cstring> + </property> + <property name="text"> + <string>&Enter string:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pComboBox</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Enter string<b/> +<br/> +Enter or choose string, that you want.</string> + </property> + </widget> + <spacer row="0" column="1"> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>117</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> +</widget> +<connections> + <connection> + <sender>m_pPushButtonCancel</sender> + <signal>clicked()</signal> + <receiver>KXEChooseStringDialogBase</receiver> + <slot>reject()</slot> + </connection> + <connection> + <sender>m_pPushButtonOk</sender> + <signal>clicked()</signal> + <receiver>KXEChooseStringDialogBase</receiver> + <slot>slotOk()</slot> + </connection> +</connections> +<slots> + <slot access="protected">slotOk()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxecommand.cpp b/part/kxecommand.cpp new file mode 100644 index 0000000..f197fc3 --- /dev/null +++ b/part/kxecommand.cpp @@ -0,0 +1,25 @@ +// +// C++ Implementation: kxecommand +// +// Description: +// +// +// Author: Adam Charytoniuk <achary@poczta.onet.pl>, (C) 2003 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "kxecommand.h" + +KXECommand::KXECommand(KXEDocument* pDocument) +:KCommand() +{ + m_pDocument = pDocument;; +} + + +KXECommand::~KXECommand() +{ +} + + diff --git a/part/kxecommand.h b/part/kxecommand.h new file mode 100644 index 0000000..8d05ebd --- /dev/null +++ b/part/kxecommand.h @@ -0,0 +1,37 @@ +// +// C++ Interface: kxecommand +// +// Description: +// +// +// Author: Adam Charytoniuk <achary@poczta.onet.pl>, (C) 2003 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef KXECOMMAND_H +#define KXECOMMAND_H + +#include <kcommand.h> +#include "kxedocument.h" + +/** +This is a base class for undoable commands in our application + +@author Adam Charytoniuk +*/ +class KXECommand : public KCommand +{ +public: + /** Constructor. Commands refer only to KXEDocument, not parts or views. + The KXEDocument is a class that owns KCommandHistory objcect. + */ + KXECommand(KXEDocument* pDocument); + + ~KXECommand(); + +protected: + KXEDocument* m_pDocument; +}; + +#endif diff --git a/part/kxeconfiguration.cpp b/part/kxeconfiguration.cpp new file mode 100644 index 0000000..d780add --- /dev/null +++ b/part/kxeconfiguration.cpp @@ -0,0 +1,181 @@ +/*************************************************************************** + kxeconfiguration.cpp + -------------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 "kxeconfiguration.h" +#include "kxetreeviewsettings.h" +#include "kxetextviewsettings.h" +#include "kxenewfilesettings.h" +#include "kxeprintsettings.h" +#include "kxearchiveextssettings.h" + +#include <kglobal.h> +#include <klocale.h> +#include <kdialogbase.h> +#include <kiconloader.h> + +#include <qlayout.h> + + +KXEConfiguration::KXEConfiguration() + : QObject( 0, "KXMLEditor's configuration (KXEConfiguration)" ), + m_pDialog( 0 ) +{ + // initialize all setting group objects + m_pTreeView = new KXETreeViewSettings( this, "tree view config. settings" ); + m_pTextView = new KXETextViewSettings( this, "text view config. settings" ); + m_pNewFile = new KXENewFileSettings( this, "new file config. settings" ); + m_pPrint = new KXEPrintSettings( this, "printing config. settings" ); + m_pArcExts = new KXEArchiveExtsSettings( this, "archive extension config. settings" ); + + // restore the settings from our config file + restore(); +} + +KXEConfiguration::~KXEConfiguration() +{ + if ( m_pDialog ) + delete m_pDialog; +} + +void KXEConfiguration::store( KConfig * pConfig ) const +{ + if ( ! pConfig ) + pConfig = KGlobal::config(); + + m_pTreeView->store( pConfig ); + m_pTextView->store( pConfig ); + m_pNewFile->store( pConfig ); + m_pPrint->store( pConfig ); + m_pArcExts->store( pConfig ); +} + + +void KXEConfiguration::restore( KConfig * pConfig ) +{ + if ( ! pConfig ) + pConfig = KGlobal::config(); + + m_pTreeView->restore( pConfig ); + m_pTextView->restore( pConfig ); + m_pNewFile->restore( pConfig ); + m_pPrint->restore( pConfig ); + m_pArcExts->restore( pConfig ); +} + + +void KXEConfiguration::showDialog() +{ + if ( ! m_pDialog ) // if there is no dialog yet, + { + // create one + m_pDialog = new KDialogBase( KDialogBase::IconList, // dialog face + i18n("Configure KXMLEditor"), // caption + KDialogBase::Apply | KDialogBase::Ok | KDialogBase::Cancel | KDialogBase::Help, // buttons + KDialogBase::Ok, // default button + 0, // parent + "configuration dialog", // name + false, // not modal + true ); // show separator + connect( m_pDialog, SIGNAL(applyClicked()), this, SLOT(slotDlgApplied()) ); + connect( m_pDialog, SIGNAL(okClicked()), this, SLOT(slotDlgApplied()) ); + + // and add the pages + QFrame * pFrame; + QWidget * pPage; + QVBoxLayout * pLayout; + + // - tree view properties page + pFrame = m_pDialog->addPage( m_pTreeView->dialogPageName(), + m_pTreeView->dialogPageHeader(), + KGlobal::instance()->iconLoader()->loadIcon( m_pTreeView->dialogPageIcon(), KIcon::NoGroup, KIcon::SizeMedium ) ); + pLayout = new QVBoxLayout( pFrame ); + pPage = m_pTreeView->dialogPage( pFrame ); + pLayout->addWidget( pPage ); + connect( m_pTreeView, SIGNAL(sigDialogPageChanged()), this, SLOT(slotDlgChanged()) ); + + // - text view properties page + pFrame = m_pDialog->addPage( m_pTextView->dialogPageName(), + m_pTextView->dialogPageHeader(), + KGlobal::instance()->iconLoader()->loadIcon( m_pTextView->dialogPageIcon(), KIcon::NoGroup, KIcon::SizeMedium ) ); + pLayout = new QVBoxLayout( pFrame ); + pPage = m_pTextView->dialogPage( pFrame ); + pLayout->addWidget( pPage ); + connect( m_pTextView, SIGNAL(sigDialogPageChanged()), this, SLOT(slotDlgChanged()) ); + + // - new file settings page + pFrame = m_pDialog->addPage( m_pNewFile->dialogPageName(), + m_pNewFile->dialogPageHeader(), + KGlobal::instance()->iconLoader()->loadIcon( m_pNewFile->dialogPageIcon(), KIcon::NoGroup, KIcon::SizeMedium ) ); + pLayout = new QVBoxLayout( pFrame ); + pPage = m_pNewFile->dialogPage( pFrame ); + pLayout->addWidget( pPage ); + connect( m_pNewFile, SIGNAL(sigDialogPageChanged()), this, SLOT(slotDlgChanged()) ); + + // - printing's settings page + pFrame = m_pDialog->addPage( m_pPrint->dialogPageName(), + m_pPrint->dialogPageHeader(), + KGlobal::instance()->iconLoader()->loadIcon( m_pPrint->dialogPageIcon(), KIcon::NoGroup, KIcon::SizeMedium ) ); + pLayout = new QVBoxLayout( pFrame ); + pPage = m_pPrint->dialogPage( pFrame ); + pLayout->addWidget( pPage ); + connect( m_pPrint, SIGNAL(sigDialogPageChanged()), this, SLOT(slotDlgChanged()) ); + + // - archive extensions page + pFrame = m_pDialog->addPage( m_pArcExts->dialogPageName(), + m_pArcExts->dialogPageHeader(), + KGlobal::instance()->iconLoader()->loadIcon( m_pArcExts->dialogPageIcon(), KIcon::NoGroup, KIcon::SizeMedium ) ); + pLayout = new QVBoxLayout( pFrame ); + pPage = m_pArcExts->dialogPage( pFrame ); + pLayout->addWidget( pPage ); + connect( m_pArcExts, SIGNAL(sigDialogPageChanged()), this, SLOT(slotDlgChanged()) ); + } + + if ( m_pDialog->isVisible() ) // If the dialog is visible (probably opened by + { // another part), it has to be hidden to make + m_pDialog->hide(); // it appear on the current desktop by the later + } // call of show. + else // If the dialog is not visible, it's + { // Apply- and Ok-buttons have to be + m_pDialog->enableButtonApply( false ); // disabled (until something is changed + m_pDialog->enableButtonOK( false ); // within the dialog). + } + + m_pDialog->show(); // show our configuration dialog +} + +void KXEConfiguration::slotDlgApplied() +{ + // reset configuration dialog + m_pDialog->enableButtonApply( false ); + m_pDialog->enableButtonOK( false ); + + // apply the page's data to the corresponding setting groups + m_pTreeView->apply(); + m_pTextView->apply(); + m_pNewFile->apply(); + m_pPrint->apply(); + m_pArcExts->apply(); + + // store the applied data to our config file + store(); +} + +void KXEConfiguration::slotDlgChanged() +{ + m_pDialog->enableButtonApply( true ); + m_pDialog->enableButtonOK( true ); +} diff --git a/part/kxeconfiguration.h b/part/kxeconfiguration.h new file mode 100644 index 0000000..3afd8b2 --- /dev/null +++ b/part/kxeconfiguration.h @@ -0,0 +1,123 @@ +/*************************************************************************** + kxeconfiguration.h + ------------------ + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 KXECONFIGURATION_H +#define KXECONFIGURATION_H + +#include <qobject.h> + +class KXETreeViewSettings; +class KXETextViewSettings; +class KXENewFileSettings; +class KXEPrintSettings; +class KXEArchiveExtsSettings; + +class KConfig; +class KDialogBase; + +/** + * This class is a container for KXMLEditor's configuration data. + * It consists of objects for the different groups of settings + * (objects of child classes of KXESettings) and manages the configuration + * dialog (@ref m_pDialog). This dialog consists of one page per settings + * group, that are initialized by them (using their dialogPage* functions). + * + * @short container for KXMLEditor's configuration data + * @author Olaf Hartig + */ +class KXEConfiguration : public QObject +{ + Q_OBJECT + + public: + + /** + * The constructor initializes the configuration setting groups + * (objects of KXESettings' child classes) and restores the + * configuration data from the config file by calling @ref restore. + */ + KXEConfiguration(); + /** + * The destructor deletes the configuration dialog, if there is one. + */ + ~KXEConfiguration(); + + /** + * Stores all configuration to the given @ref KConfig object by + * using @ref KXESettings's @ref store function. + * If no @ref KConfig object is given, @ref KGlobal::config is + * used. + */ + void store( KConfig * pConfig = 0 ) const; + /** + * Restores all configuration from the given @ref KConfig object + * by using @ref KXESettings's @ref restore function. + * If no @ref KConfig object is given, @ref KGlobal::config is + * used. + */ + void restore( KConfig * pConfig = 0 ); + /** + * Shows the configuration dialog. + * If there is no one yet, it is created by. + */ + void showDialog(); + + // The following functions return pointers to the configuration setting + // groups (objects of KXESettings' child classes), that can be used to + // access their data (or to connect to their signals). + + KXETreeViewSettings * const treeview() const { return m_pTreeView; } + KXETextViewSettings * const textview() const { return m_pTextView; } + KXENewFileSettings * const newfile() const { return m_pNewFile; } + KXEPrintSettings * const print() const { return m_pPrint; } + KXEArchiveExtsSettings * const archexts() const { return m_pArcExts; } + + protected slots: + + /** + * Applies the new data in the dialog's pages to our setting groups + * by using @ref KXESettings's @ref apply function and stores + * all settings with @ref store. + * After applying, the dialog's state is reseted (disabled Apply- and + * OK-buttons). + */ + void slotDlgApplied(); + /** + * Enables the configuration dialog's Apply- and OK-button. + */ + void slotDlgChanged(); + + protected: + + // The following members are the configuration setting + // groups (objects of KXESettings' child classes). + + KXETreeViewSettings * m_pTreeView; + KXETextViewSettings * m_pTextView; + KXENewFileSettings * m_pNewFile; + KXEPrintSettings * m_pPrint; + KXEArchiveExtsSettings * m_pArcExts; + + /** + * This is a pointer to our configuration dialog. + * The dialog itself is created on demand in @ref showDialog. + * It consists of one page per settings group. + */ + KDialogBase * m_pDialog; +}; + +#endif diff --git a/part/kxedocument.cpp b/part/kxedocument.cpp new file mode 100644 index 0000000..c3775c5 --- /dev/null +++ b/part/kxedocument.cpp @@ -0,0 +1,631 @@ +// +// C++ Implementation: kxedocument +// +// Description: +// +// +// Author: Adam Charytoniuk <achary@poczta.onet.pl>, (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "kxedocument.h" + +#include "kxmleditorfactory.h" +#include "kxeconfiguration.h" +#include "kxenewfilesettings.h" +#include "kxearchiveextssettings.h" +#include "kxeprintsettings.h" +#include "kxetextviewsettings.h" +#include "kxechoosestringdialog.h" +#include "kxeattachdialogbase.h" +#include "kxespecprocinstrdialog.h" +#include "kxefilenewdialog.h" +#include "commands_file.h" + + +#include <kfile.h> +#include <ktar.h> +#include <kzip.h> +#include <kfilterdev.h> +#include <ktempfile.h> +#include <kdebug.h> +#include <kmessagebox.h> +#include <klocale.h> +#include <kcommand.h> +#include <kaction.h> +#include <kurl.h> +#include <kurlrequester.h> + +#include <qcombobox.h> +#include <qbuffer.h> +#include <qregexp.h> +#include <qtextcodec.h> +#include <qlabel.h> +#include <qcheckbox.h> + +KXEDocument::KXEDocument(QObject *parent, const char *name) + :QObject (parent,name), + QDomDocument(), + KXMLGUIClient() +{ + m_bDocIsCompressed = false; + m_bIsModified = false; + m_strCompressedTarEntryName = ""; + m_url = ""; + + //setXMLFile("kxedocument.rc"); +} + + +KXEDocument::~KXEDocument() +{ +} + + +bool KXEDocument::save(const QString &strFileName) +{ + if (this->documentElement().isNull() && + KMessageBox::warningContinueCancel(0, + i18n("Your file doesn't have root element defined. \n\ + Continue saving?"))==KMessageBox::Cancel ) + { + return false; + } + + QString strXML; + + QTextStream streamXML(&strXML, IO_WriteOnly); + int iIndent = KXMLEditorFactory::configuration()->textview()->indentSteps(); + ((QDomDocument*)this)->save(streamXML, iIndent); + + QString strEncoding; + QTextCodec *pTextCodec; + + // find encoding info + if(strXML.left(5) == "<?xml") + { int iStart, iEnd; + if((iStart = strXML.find("encoding", 0)) > 0) + { + // info about encoding found; + iStart += 8; // skip encoding + + // search " or ' after encoding + if((iStart = strXML.find(QRegExp("[\"']"), iStart)) > 0) + { + QChar ch = strXML[iStart]; + iStart++; // skip ch + if((iEnd = strXML.find(ch, iStart)) > 0) + { + strEncoding = strXML.mid(iStart, iEnd - iStart); + } + } + } + } + + if(strEncoding.length() <= 0) + pTextCodec = QTextCodec::codecForLocale(); // default + else + pTextCodec = QTextCodec::codecForName(strEncoding); + + if(pTextCodec == 0) + { if(KMessageBox::questionYesNo(0, i18n("Codec for encoding %1 not found ! Continue saving ?").arg(strEncoding)) != KMessageBox::Yes) + return false; + } + + QCString strDecoded; + if(pTextCodec) + { strDecoded = pTextCodec->fromUnicode(strXML); + } + + // save string to file + if(!m_bDocIsCompressed) + { QFile file(strFileName); + if(file.open(IO_WriteOnly) == true) + { file.writeBlock(strDecoded, strDecoded.length()); + file.flush(); + file.close(); + } + else + { KMessageBox::error(0, + i18n("Can't create file %1").arg(strFileName), + i18n("Write error !")); + } + } + else + { // obtain file extension ----------------------------------------- + QString strExtension; + + int iPos = strFileName.findRev('.'); + + if(iPos > 0) + { strExtension = strFileName.mid(iPos + 1); + } + + if(strExtension == "svgz") + { + KMessageBox::sorry(0, + "Saving *.svgz not implemented yet", + "sory"); + return false; + } + else + { + KZip tarGzFile(strFileName); // New KOffice use KZip instead of KTarGz for storing files + if(tarGzFile.open(IO_WriteOnly)) + { tarGzFile.writeFile(m_strCompressedTarEntryName, "user", "group", strDecoded.length(), strDecoded); + tarGzFile.close(); + } + else + { KMessageBox::error(0, + i18n("Can't create archive %1").arg(strFileName), + i18n("Write error !")); + } + } + } + + return true; +} + +bool KXEDocument::open(const QString &strFileName) +{ + QString strCompressedTarEntryName; + + kdDebug() << "KXEDocument::open: opening file " << strFileName << endl; + + // obtain file extension ----------------------------------------- + QString strExtension; + + int iPos = strFileName.findRev('.'); + + if(iPos > 0) + { strExtension = strFileName.mid(iPos + 1); + } + + QString strTmpfileName; + + if ( KXMLEditorFactory::configuration()->archexts()->extensions().contains(strExtension) ) + { + + KTempFile tmp; + if (tmp.status() != 0) + { + kdError() << "Couldn't open temp file" << endl; + KMessageBox::sorry(0, i18n("Couldn't open temp file !")); + return false; + } + + tmp.setAutoDelete(false); + QFile &fileTemporary = *(tmp.file()); + + + if(strExtension == "svgz") + { + //----------------------- It is gzip compressed file ----------------------- + + m_strCompressedTarEntryName = strFileName.left(strFileName.length() - 5); // For SVG compressed icons strip extension, e.g. "kate.svgz" has entry "kate" etc + + iPos = m_strCompressedTarEntryName.findRev('/'); + + if(iPos > 0) + { m_strCompressedTarEntryName = m_strCompressedTarEntryName.mid(iPos + 1); + } + + QIODevice *pIODevice = KFilterDev::deviceForFile(strFileName, "application/x-gzip"); + + if(pIODevice->open( IO_ReadOnly )) + { + QTextStream stream(pIODevice); + QString line; + //int i = 1; + while ( !stream.atEnd() ) + { + line = stream.readLine(); // line of text excluding '\n' + //printf( "%3d: %s\n", i++, line.latin1() ); + fileTemporary.writeBlock(line, line.length()); + } + pIODevice->close(); + } + } + else + { + //----------------------- It is zip archive file --------------------------- + + KZip tarGzFile(strFileName); // new KOffice use KZip instead of KTarGz for storing files + + tarGzFile.open(IO_ReadOnly); + fileTemporary.open(IO_WriteOnly); + + const KTarDirectory *root = tarGzFile.directory(); + if(!root) + { + return false; + } + + // For KOffice files let user to choose maindoc or documentinfo + if(strCompressedTarEntryName.length() == 0) + { KXEChooseStringDialog dlgChooseString(0, 0, i18n("Choose file"), i18n("File:")); + dlgChooseString.m_pComboBox->insertItem("maindoc.xml"); + dlgChooseString.m_pComboBox->insertItem("documentinfo.xml"); + + if(dlgChooseString.exec() != KXEChooseStringDialog::Accepted) + { return false; + } + m_strCompressedTarEntryName = dlgChooseString.m_strChoosedText; + } + else + { + m_strCompressedTarEntryName = strCompressedTarEntryName; + } + + const KArchiveEntry *entry = root->entry(m_strCompressedTarEntryName); + + if(entry && entry->isFile()) + { const KArchiveFile *pTarFile = static_cast <const KArchiveFile *> (entry); + + QBuffer buffer(pTarFile->data()); + buffer.open(IO_ReadOnly); + + fileTemporary.writeBlock(buffer.buffer(), buffer.size()); + } + else + m_strCompressedTarEntryName.truncate(0); + + tarGzFile.close(); + } + + strTmpfileName = fileTemporary.name(); + fileTemporary.close(); + + m_bDocIsCompressed = true; + } + else + m_bDocIsCompressed = false; + + + // ( 1.) parse the file and fill our document + QFile file(m_bDocIsCompressed ? strTmpfileName : strFileName); + if(! file.open(IO_ReadOnly)) + { + kdDebug() << "KXEDocument::openFile: Can't open file." << endl; + return false; + } + + // auxiliary file for obtaining encoding info + QFile fileAux(m_bDocIsCompressed ? strTmpfileName : strFileName); + if(! fileAux.open(IO_ReadOnly)) + { + kdDebug() << "KXEDocument::openFile: Can't open file." << endl; + return false; + } + + QTextStream txtStreamLocal( & file ); + + // Lookup at XML document encoding ----------------------------------------------- + QTextStream txtStreamAux( & fileAux ); + QString strFirstLine = txtStreamAux.readLine(); + fileAux.close(); + int iStart, iEnd; + if((iStart = strFirstLine.find("encoding", 0)) > 0) + { + QString strEncoding; + // info about encoding found; + iStart += 8; // skip encoding + + // search " or ' after encoding + if((iStart = strFirstLine.find(QRegExp("[\"']"), iStart)) > 0) + { + QChar ch = strFirstLine[iStart]; + iStart++; // skip ch + if((iEnd = strFirstLine.find(ch, iStart)) > 0) + { + strEncoding = strFirstLine.mid(iStart, iEnd - iStart); + + QTextCodec *pTextCodec = QTextCodec::codecForName(strEncoding); + if(pTextCodec) + txtStreamLocal.setCodec(pTextCodec); + else + { + KMessageBox::sorry(0, i18n("Codec for encoding %1 not found ! Using locale encoding for load.").arg(strEncoding)); + txtStreamLocal.setEncoding(QTextStream::Locale); + } + } + } + } + else + { + // XML documment dont have info about encoding, set default UTF-8 + txtStreamLocal.setCodec(QTextCodec::codecForName("UTF-8")); + } + + + //-------------------------------------------------------------------------------- + QString strFileContents = txtStreamLocal.read(); + file.close(); + + if(m_bDocIsCompressed) + { + QDir dir; + dir.remove(strTmpfileName); + } + + //-- Set string with XML to QDomDocument ------------------------------------------ + QString strErrorMsg; + int iErrorLine, iErrorColumn; + QDomDocument * pNewDoc = new QDomDocument; // first try with a new document + + if( ! pNewDoc->setContent(strFileContents, true, &strErrorMsg, &iErrorLine, &iErrorColumn) ) + { kdDebug() << "KXEDocument::openFile: Failed parsing the file." << endl; + + KMessageBox::error(0, + i18n("%1 in line %2, column %3").arg(strErrorMsg).arg(iErrorLine).arg(iErrorColumn), + i18n("Parsing error !")); + + delete pNewDoc; // remove the new document, because it's useless + return false; + } + +// The following commented code is performance wise buggy, because the string +// gets parsed a second time. I replaced it with this code. + // copy the content of the parsed document to this one + QDomNode e = pNewDoc->removeChild( pNewDoc->documentElement() ); + QDomDocument::operator=( *pNewDoc ); + appendChild( e ); +// Here comes the "buggy" code. + //this->setContent(pNewDoc->toString(),true,0,0); // and take the new one + //delete pNewDoc; // remove the former document +// To test/see the difference in loading time, you can switch the commented +// codeblocks above and compare the loading-time-differences measured in +// KXMLEditorPart::openFile. +// Olaf +// TODO: remove the comments above later + + emit sigOpened(); + + return true; +} + +void KXEDocument::setModified(bool value) +{ + m_bIsModified = value; + emit sigModified(value); +} + +void KXEDocument::setURL(KURL url) +{ + m_url = url; + emit sigURLChanged(url); +} + +void KXEDocument::updateNodeCreated(const QDomNode & node) +{ + emit sigNodeCreated(node); + setModified(); +} + +void KXEDocument::updateNodeDeleted(const QDomNode & node) +{ + emit sigNodeDeleted(node); + setModified(); +} + +void KXEDocument::updateNodeChanged( const QDomElement & domElement ) +{ + emit sigNodeChanged(domElement); + setModified(); +} + +void KXEDocument::updateNodeChanged( const QDomCharacterData & node ) +{ + emit sigNodeChanged(node); + setModified(); +} + +void KXEDocument::updateNodeChanged( const QDomProcessingInstruction &domProcInstr ) +{ + emit sigNodeChanged(domProcInstr); + setModified(); +} + +void KXEDocument::updateNodeMoved( const QDomNode & node ) +{ + emit sigNodeMoved(node); + setModified(); +} + +void KXEDocument::attachStylesheet(const KURL& stylesheet) +{ + setSpecProcInstr("xml-stylesheet",QString("type = 'text/xsl' href = '")+stylesheet.url()+"' "); +} + +void KXEDocument::detachStylesheet() +{ + removeSpecProcInstr("xml-stylesheet"); +} + +void KXEDocument::attachSchema(const KURL& schema) +{ + QDomElement domElement = documentElement(); + if (!domElement.isNull()) + { + domElement.setAttributeNS(SCHEMA_NAMESPACE, + SCHEMA_ATTRIBUTE_XSI, + schema.url()); + // refresh views + updateNodeChanged(domElement); + setModified(); + } +} + +void KXEDocument::detachSchema() +{ + QDomElement domElement = this->documentElement(); + if (!domElement.isNull()) + { + domElement.removeAttributeNS(SCHEMA_NAMESPACE,SCHEMA_ATTRIBUTE); + // refresh views + updateNodeChanged(domElement); + setModified(); + } +} + +void KXEDocument::setSpecProcInstr(const QString& target, const QString& data) +{ + // removing old one + removeSpecProcInstr(target); + // create new one + if (!data.isEmpty()) + { + QDomProcessingInstruction domProcInstr = this->createProcessingInstruction(target,data); + + QDomNode node = getSpecProcInstr("xml"); + if (!node.isNull()) + // if there is already xml instruction, then put that one below it + this->insertAfter(domProcInstr,node); + else + // otherwise put it always on the top + this->insertBefore(domProcInstr,this->firstChild()); + + updateNodeCreated(domProcInstr); + } + setModified(); +} + +void KXEDocument::removeSpecProcInstr(const QString &target) +{ + QDomNode domNode = getSpecProcInstr(target); + if (!domNode.isNull()) + { + updateNodeDeleted(domNode); + ((QDomDocument*)this)->removeChild(domNode); + setModified(); + } +} + +QDomNode KXEDocument::getSpecProcInstr(const QString& target) +{ + QDomNode result; + QDomNodeList domNodeList = this->childNodes(); + for (uint i=0;i<domNodeList.count();i++) + if (domNodeList.item(i).isProcessingInstruction()) + { + QDomProcessingInstruction domProcInstr = domNodeList.item(i).toProcessingInstruction(); + if (domProcInstr.target()==target) + return domNodeList.item(i); + } + return result; +} + +void KXEDocument::newFile() +{ + switch ( KXMLEditorFactory::configuration()->newfile()->newFileCreaBehav() ) + { + case KXENewFileSettings::CreateEmptyFile: + break; // nothing to do in this case + + case KXENewFileSettings::CreateWithAssistance: + { + + KXEFileNewDialog dlg( 0L); + dlg.fillDialog( KXMLEditorFactory::configuration()->newfile()->dfltVersion(), + KXMLEditorFactory::configuration()->newfile()->dfltEncoding() ); + if( dlg.exec() ) + { // if the dialog has been accepted (OK pressed) + setSpecProcInstr( "xml", dlg.getData() ); + + // if the dialog shouldn't be shown anymore, the settings have to be changed + if ( dlg.m_pDontShowAgain->isChecked() ) + KXMLEditorFactory::configuration()->newfile()->setNewFileCreaBehav( KXENewFileSettings::UseDefaults, instance()->config() ); + } + + break; + } + + case KXENewFileSettings::UseDefaults: + setSpecProcInstr( "xml", QString( "version='%1' encoding='%2'" ).arg(KXMLEditorFactory::configuration()->newfile()->dfltVersion()).arg(KXMLEditorFactory::configuration()->newfile()->dfltEncoding()) ); + break; + } + emit sigOpened(); + setModified(); +} + +//------------- SLOTS, called from Part -------------------------------- + +KCommand * KXEDocument::actDetachStylesheet() +{ + QDomNode domNode = getSpecProcInstr("xml-stylesheet"); + if (!domNode.isNull()) + { + KCommand *pCmd = new KXEStylesheetDetachCommand(this,domNode.toProcessingInstruction().data()); + return pCmd; + } + return 0L; +} + +KCommand * KXEDocument::actAttachStylesheet() +{ + KXEAttachDialogBase dlg; + dlg.Label->setText(i18n("Stylesheet URL:")); + if (dlg.exec()) + { + QDomNode domNode = getSpecProcInstr("xml-stylesheet"); + QString data = ""; + if (!domNode.isNull()) + data = domNode.toProcessingInstruction().data(); + KCommand *pCmd = new KXEStylesheetAttachCommand(this,data,dlg.attachURI->url()); + return pCmd; + } + return 0L; +} + +KCommand * KXEDocument::actDetachSchema() +{ + if (!documentElement().isNull()) // just for sure... + { + KCommand *pCmd = new KXESchemaDetachCommand(this, + documentElement().attributeNS(SCHEMA_NAMESPACE, + SCHEMA_ATTRIBUTE,"") + ); + return pCmd; + } + return 0L; +} + +KCommand * KXEDocument::actAttachSchema() +{ + KXEAttachDialogBase dlg; + dlg.Label->setText(i18n("Schema URL:")); + if (dlg.exec()) + { + if (!documentElement().isNull()) // just for sure... + { + KCommand *pCmd = new KXESchemaAttachCommand(this,dlg.attachURI->url(), + documentElement().attributeNS(SCHEMA_NAMESPACE,SCHEMA_ATTRIBUTE,"")); + return pCmd; + } + } + return 0L; +} + +// Instert or edit special processing instruction <?xml ... ?> +KCommand * KXEDocument::actVersionEncoding() +{ + QDomNode node = getSpecProcInstr("xml"); + KXESpecProcInstrDialog dlg; + + if(!node.isNull()) + dlg.fillDialog(node.toProcessingInstruction().data()); + else + dlg.fillDialog( KXMLEditorFactory::configuration()->newfile()->dfltVersion(), + KXMLEditorFactory::configuration()->newfile()->dfltEncoding() ); + + if(dlg.exec()) + { + QString strOldData = ""; + if (!node.isNull()) + strOldData = node.toProcessingInstruction().data(); + KCommand *pCmd = new KXEVersionEncodingCommand(this,strOldData,dlg.getData()); + return pCmd; + } + return 0L; +} diff --git a/part/kxedocument.h b/part/kxedocument.h new file mode 100644 index 0000000..2b78659 --- /dev/null +++ b/part/kxedocument.h @@ -0,0 +1,240 @@ +// +// C++ Interface: kxedocument +// +// Description: +// +// +// Author: Adam Charytoniuk <achary@poczta.onet.pl>, (C) 2004 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef KXEDOCUMENT_H +#define KXEDOCUMENT_H + +#include <kurl.h> + +#include <qobject.h> +#include <qdom.h> +#include <kparts/part.h> +#include <kxmlguiclient.h> + +#define SCHEMA_NAMESPACE "http://www.w3.org/2001/XMLSchema-instance" +#define SCHEMA_ATTRIBUTE "schemaLocation" +#define SCHEMA_ATTRIBUTE_XSI "xsi:schemaLocation" + +class QString; +class KCommand; + + +/** +@file +*/ + +/** +@short Base class for documents in KXMLEditor. + +Stores XML document data which can be manipulated by KXMLEditor application. + + +@author Adam Charytoniuk +*/ +class KXEDocument : public QObject, public QDomDocument, public KXMLGUIClient +{ + Q_OBJECT +public: + /** @short Constructor */ + KXEDocument(QObject *parent=0, const char *name=0); + + /** @short Destructor */ + ~KXEDocument(); + + /** @short Saves document into given file */ + bool save(const QString &); + + /** @short Loads document from given file */ + bool open(const QString &); + + /** @short Sets modification flag. + + Should be called after every operation done on the document content */ + void setModified(bool value=true); + + /** @short Returns true if this document was modified and not saved yet */ + bool isModified() {return m_bIsModified;} + + /** @short Changes document url */ + void setURL(KURL url); + + /** @short Executes given command and adds it into internal document command history list + + @param pCmd pointer to KXECommand object which encapsulates required operations + on a document content + */ + + /** @short Notifies views about creating new element + + @param node newly created node + */ + void updateNodeCreated(const QDomNode & node); + + /** @short Notifies views about deleting node + + This should be called before given node from the document will be deleted. + This will give a chanse to the views to remove that node visualization. + @param node that is going to be deleted + */ + void updateNodeDeleted(const QDomNode & node); + + /** @short Notifies views about element properties changes + + Should be called after element name or element attributes are changed. + @param domElement element that has changed + */ + void updateNodeChanged( const QDomElement & domElement ); + + /** @short Notifies views after change char. data properties + + Should be called after any kind of character data is changed + (including texts, comments, .CDATA sections). + @param node character data node that has changed + */ + void updateNodeChanged( const QDomCharacterData & node ) ; + + /** @short Notifies views after change proc. instr. properties + + Should be called after any processing intruction is changed. + @param domProcInstr processing instruction that has changed + */ + void updateNodeChanged( const QDomProcessingInstruction &domProcInstr ); + + /** @short Notifies views after moving node + + Should be called if any node in the document was moved. + @param node XML node that has been moved + */ + void updateNodeMoved( const QDomNode & node ); + + /** @short Removes spec. processing instruction from XML file. + + @param target name of the proc. instruction target + @warning Removes processing instruction from DomDocument children node list only (no subnodes are modiified). + @sa setSpecProcInstr() + */ + void removeSpecProcInstr(const QString &target); + + /** @short Adds or changes (if already exists) processing instruction. + + Processing instruction will be added as a child in QDomDocument object. + @param target processing intruction target + @param data processing intruction data + @sa removeSpecProcInstr() + */ + virtual void setSpecProcInstr(const QString& target, const QString& data); + + /** @short Returns processing instruction located in QDomDocument. + + If given processing intruction is not found, null node is returned. + @param target name of the processing instruction target. + @sa setSpecProcInstr() + */ + QDomNode getSpecProcInstr(const QString& target); + + /** @short Attaches stylesheet to current XML file. + + If file is already attached to stylesheet, this attachment will be overriten. + @param stylesheet url to stylesheet location + @sa detachStylesheet() + */ + virtual void attachStylesheet(const KURL& stylesheet); + + /** @short Detaches stylesheet from current XML file. + + @sa attachStylesheet()*/ + virtual void detachStylesheet(); + + /** Attaches schema to current XML file. If file is already attached to schema, + this attachment will be overriten. + @param schema url to schema location + @sa detachSchema()*/ + virtual void attachSchema(const KURL& schema); + + /** @short Detaches schema from current XML file. + + @sa attachSchema()*/ + virtual void detachSchema(); + + /** @short prepares content of newly created document. + + The preparation will be done accordingly to settings. + In addition, signal sigOpened() is emited to notify all views + about the change.*/ + virtual void newFile(); + + + /** @short Inserts special proc.instruction into document. */ + KCommand * actVersionEncoding(); + + /** @short Called on user's action response. + + Creates <?xml-stylesheet ...?> processing instruction + with reference to specified stylesheet URI. + */ + KCommand * actAttachStylesheet(); + + /** @short Called on user's action response. */ + KCommand * actDetachStylesheet(); + + /** @short Called on user's action response */ + KCommand * actDetachSchema(); + + /** @short Called on user's action response */ + KCommand * actAttachSchema(); + +private: + QString m_strCompressedTarEntryName; + /** Equals true if document was opened from compressed file */ + bool m_bDocIsCompressed; + /** @short Stores modification flag */ + bool m_bIsModified; + KURL m_url; + +signals: + /** @short Emmited when document has a new content. + + This may happen in the following scenarios: + - document was opened from the fille or URL, + - document has modified big part of the content + - document initialized it's content after creations + + @sa newFile() + */ + void sigOpened(); + + /** @short Emitted when document content have been changed. + + This allows to notify all attached views about that event.*/ + void sigModified(bool value); + + void sigURLChanged(KURL url); + /** @short Emitted when new node was added to document.*/ + void sigNodeCreated(const QDomNode & node); + /** @short Emitted everytime node was deleted from document.*/ + void sigNodeDeleted(const QDomNode & node); + /** @short Emitted everytime document element was changed .*/ + void sigNodeChanged( const QDomElement & domElement ); + /** @short Emitted everytime character data node was changed. + + This is the case for nodes like: + - text, + - comments, + - CDATA sections, + */ + void sigNodeChanged( const QDomCharacterData & node ) ; + /** @short Emitted everytime processing instruction in document was changed .*/ + void sigNodeChanged( const QDomProcessingInstruction &domProcInstr ); + /** @short Emitted everytime document node was moved was changed .*/ + void sigNodeMoved( const QDomNode & node ); +}; + +#endif diff --git a/part/kxedocument.rc b/part/kxedocument.rc new file mode 100644 index 0000000..b580dee --- /dev/null +++ b/part/kxedocument.rc @@ -0,0 +1,15 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui name="kxedocument" version="1"> +<!-- document specific actions here --> +<MenuBar> + <Menu name="file"><text>&File</text> + <Action name="xml_ins_spec_procins"/> + <Separator lineSeparator="true"/> + <Action name="xml_attach_schema"/> + <Action name="xml_detach_schema"/> + <Action name="xml_attach_stylesheet"/> + <Action name="xml_detach_stylesheet"/> + <Separator lineSeparator="true"/> + </Menu> +</MenuBar> +</kpartgui> diff --git a/part/kxeelementdialog.cpp b/part/kxeelementdialog.cpp new file mode 100644 index 0000000..b9736b1 --- /dev/null +++ b/part/kxeelementdialog.cpp @@ -0,0 +1,189 @@ +/*************************************************************************** + kxeelementdialog.cpp - description + ------------------- + begin : Mit Apr 17 2002 + copyright : (C) 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 "kxeelementdialog.h" + +#include <qlabel.h> +#include <qcombobox.h> +#include <qpushbutton.h> + +#include <klineedit.h> +#include <kdebug.h> +#include <klocale.h> + +KXEElementDialog::KXEElementDialog( QWidget * pParent, const char * pszName, bool fModal, WFlags fl ) + : KXEElementDialogBase( pParent, pszName, fModal, fl ) +{ + connect( m_pEditNsURI, SIGNAL(textChanged(const QString&)), this, SLOT(slotNsURIChanged(const QString&)) ); + connect( m_pEditName, SIGNAL(textChanged(const QString&)), this, SLOT(slotNameChanged(const QString&)) ); +} + +void KXEElementDialog::clearDialog() +{ + m_pEditNsURI->clear(); + m_pEditNsURI->setEnabled(true); + m_pEditNsURI->show(); + m_pLblNsURI->setEnabled(true); + m_pLblNsURI->show(); + + m_pEditPrefix->clear(); + m_pEditPrefix->setDisabled(true); + m_pEditPrefix->show(); + m_pLblPrefix->setEnabled(true); + m_pLblPrefix->show(); + + m_pEditName->clear(); + + m_pComboInsert->setCurrentItem(0); +} + +void KXEElementDialog::fillDialog( bool bNsURIIsNull ) +{ + m_pEditNsURI->setDisabled(true); + + if ( bNsURIIsNull ) + { + m_pEditNsURI->hide(); + m_pLblNsURI->hide(); + m_pLblNsURI->setDisabled(true); + + m_pEditPrefix->setDisabled(true); + m_pEditPrefix->hide(); + m_pLblPrefix->hide(); + m_pLblPrefix->setDisabled(true); + } + else + { + m_pEditNsURI->setText( m_strNsURI ); + m_pEditNsURI->show(); + m_pLblNsURI->show(); + m_pLblNsURI->setEnabled(true); + + m_pEditPrefix->setText( m_strPrefix ); + m_pEditPrefix->setEnabled(true); + m_pEditPrefix->show(); + m_pLblPrefix->show(); + m_pLblPrefix->setEnabled(true); + } + + m_pComboInsert->hide(); + m_pComboInsert->setDisabled(true); + m_pLblInsert->hide(); + m_pLblInsert->setDisabled(true); + + m_pEditName->setText( m_strName ); +} + +int KXEElementDialog::exec( bool bEditExisting, bool bRootElement, bool bNsURIIsNull ) +{ + if(bEditExisting) + { + fillDialog( bNsURIIsNull ); + } + else + { + if( bRootElement ) + { + m_pComboInsert->hide(); + m_pComboInsert->setDisabled(true); + m_pLblInsert->hide(); + m_pLblInsert->setDisabled(true); + } + + clearDialog(); + } + + int iReturn = exec(); + if ( iReturn == Accepted ) + { + m_strNsURI = m_pEditNsURI->text(); + m_strPrefix = m_pEditPrefix->text(); + m_strName = m_pEditName->text(); + + m_bAtTop = ( m_pComboInsert->currentItem() == 0 ); + } + + return iReturn; +} + +int KXEElementDialog::exec() +{ + if ( m_pEditName->text().isEmpty() ) + m_pBtnOK->setEnabled(false); + else + m_pBtnOK->setEnabled(true); + + m_pEditName->setFocus(); + m_pBtnOK->setDefault(true); + + return KXEElementDialogBase::exec(); +} + +void KXEElementDialog::slotNsURIChanged( const QString & strNewNsURI ) +{ + if ( strNewNsURI.isEmpty() ) + m_pEditPrefix->setEnabled(false); + else + m_pEditPrefix->setEnabled(true); +} + +void KXEElementDialog::slotNameChanged( const QString & strNewName ) +{ + QString strMessage = checkName(strNewName); + + m_pTextLabelMessage->setText(strMessage); + + if ( strNewName.isEmpty() || (strMessage.length() > 0)) + m_pBtnOK->setEnabled(false); + else + m_pBtnOK->setEnabled(true); +} + +// Check, if XML element name is OK +QString KXEElementDialog::checkName(const QString strElementName) +{ + if(strElementName.length() == 0) + return ""; + + // test for space + if(strElementName.find(' ') >= 0) + return i18n("Element name cannot contain space !"); + + // test for xml, XML ... on start + if(strElementName.find("xml", 0, false) == 0) + return i18n("Element name cannot start with 'xml' or 'XML' !"); + + // check first character + QChar firstChar(strElementName[0]); + if((firstChar != '_') && !firstChar.isLetter()) + { + return i18n("Element name must start with an underscore or a letter !"); + } + + // Forbidden characters + QString strForbiddenChars("&@#$%^()%+?=:<>;\"'*"); + for(unsigned int i = 0; i < strForbiddenChars.length(); i++) + { + QChar ch = strForbiddenChars[i]; + + if(strElementName.find(ch) >= 0) + return i18n("Element name cannot contain character: %1 !").arg(ch); + } + + return ""; +} + diff --git a/part/kxeelementdialog.h b/part/kxeelementdialog.h new file mode 100644 index 0000000..8012525 --- /dev/null +++ b/part/kxeelementdialog.h @@ -0,0 +1,92 @@ +/*************************************************************************** + kxeelementdialog.h - description + ------------------ + begin : Mit Apr 17 2002 + copyright : (C) 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 KXEELEMENTDIALOG_H +#define KXEELEMENTDIALOG_H + +#include "kxeelementdialogbase.h" + +class KXEElementDialog : public KXEElementDialogBase +{ + Q_OBJECT + + public: + KXEElementDialog( QWidget * pParent = 0, const char * pszName = 0, bool fModal = true, WFlags fl = 0 ); + + public: + + const QString nsURI() const { return m_strNsURI; } + const QString prefix() const { return m_strPrefix; } + const QString name() const { return m_strName; } + const bool atTop() const { return m_bAtTop; } + + void setNsURI(const QString strNsURI) { m_strNsURI = strNsURI; } + void setPrefix(const QString strPrefix) { m_strPrefix = strPrefix; } + void setName(const QString strName) { m_strName = strName; } + + /** + * To be used for creating a new XML element + * + * @return see @ref QDialog::exec + */ + int exec( bool, bool, bool ); + + // check element name + static QString checkName(const QString); + + protected: + /** + * Clears the dialogs widgets (removes their content). + */ + + void clearDialog(); + + /** + * Fills the dialogs widgets with the data members. + */ + void fillDialog( bool ); + + /** + * Don't use this function directly, it's for internal use only. + * Use one of the other @ref DlgXMLElement::exec functions instead. + */ + int exec(); + /** + * Called, when the namespace URI in the edit line @ref DlgXMLElementBase::m_pEditNsURI + * is changed. + * Disables the prefix edit line (@ref DlgXMLElementBase::m_pEditPrefix), + * if the given string is empty. + */ + + + protected slots: + void slotNsURIChanged( const QString & szNewNsURI ); + /** + * Called, when the name in the edit line @ref DlgXMLElementBase::m_pEditName + * is changed. + * Disables the OK button, if the given string is empty. + */ + void slotNameChanged( const QString & szNewName ); + +protected: + QString m_strNsURI; + QString m_strPrefix; + QString m_strName; + bool m_bAtTop; +}; + +#endif diff --git a/part/kxeelementdialogbase.ui b/part/kxeelementdialogbase.ui new file mode 100644 index 0000000..0cf8cac --- /dev/null +++ b/part/kxeelementdialogbase.ui @@ -0,0 +1,339 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXEElementDialogBase</class> +<widget class="QDialog"> + <property name="name"> + <cstring>KXEElementDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>344</width> + <height>321</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>XML Element</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer row="1" column="1"> + <property name="name"> + <cstring>Spacer3</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>37</height> + </size> + </property> + </spacer> + <widget class="QLabel" row="2" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_pLblPrefix</cstring> + </property> + <property name="text"> + <string>&Prefix:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pEditPrefix</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Prefix</b> +<br/> +You can enter the namespace prefix for this XML element here.</string> + </property> + </widget> + <spacer row="3" column="1"> + <property name="name"> + <cstring>Spacer4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>37</height> + </size> + </property> + </spacer> + <spacer row="5" column="1"> + <property name="name"> + <cstring>Spacer5</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>37</height> + </size> + </property> + </spacer> + <widget class="QLineEdit" row="1" column="0"> + <property name="name"> + <cstring>m_pEditNsURI</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Namespace URI</b><br/> +You can enter the namespace URI of this XML element here.</string> + </property> + </widget> + <widget class="QLineEdit" row="5" column="0"> + <property name="name"> + <cstring>m_pEditName</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Local Name</b> +<br/> +You have to enter this XML elements name here.</string> + </property> + </widget> + <widget class="QLineEdit" row="3" column="0"> + <property name="name"> + <cstring>m_pEditPrefix</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Prefix</b> +<br/> +You can enter the namespace prefix for this XML element here.</string> + </property> + </widget> + <widget class="QLabel" row="4" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_pLblTagName</cstring> + </property> + <property name="text"> + <string>Local &Name:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pEditName</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Local Name</b> +<br/> +You have to enter this XML elements name here.</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_pLblNsURI</cstring> + </property> + <property name="text"> + <string>Namespace &URI:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pEditNsURI</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Namespace URI</b><br/> +You can enter the namespace URI of this XML element here.</string> + </property> + </widget> + <widget class="QLayoutWidget" row="8" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>0</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnOK</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string>Alt+O</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string>Alt+C</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="7" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblInsert</cstring> + </property> + <property name="text"> + <string>&Insert:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pComboInsert</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Insert</b> +<br/> +Choose, where to place this XML element in the parent elements list of childelements.</string> + </property> + </widget> + <widget class="QComboBox"> + <item> + <property name="text"> + <string>at bottom</string> + </property> + </item> + <item> + <property name="text"> + <string>at top</string> + </property> + </item> + <property name="name"> + <cstring>m_pComboInsert</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Insert</b> +<br/> +Choose, where to place this XML element in the parent elements list of childelements.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>181</width> + <height>16</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QLabel" row="6" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_pTextLabelMessage</cstring> + </property> + <property name="paletteForegroundColor"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + <property name="textFormat"> + <enum>PlainText</enum> + </property> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>m_pBtnOK</sender> + <signal>clicked()</signal> + <receiver>KXEElementDialogBase</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>m_pBtnCancel</sender> + <signal>clicked()</signal> + <receiver>KXEElementDialogBase</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>m_pEditName</tabstop> + <tabstop>m_pComboInsert</tabstop> + <tabstop>m_pBtnOK</tabstop> + <tabstop>m_pBtnCancel</tabstop> + <tabstop>m_pEditNsURI</tabstop> + <tabstop>m_pEditPrefix</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxefilenewdialog.cpp b/part/kxefilenewdialog.cpp new file mode 100644 index 0000000..807f477 --- /dev/null +++ b/part/kxefilenewdialog.cpp @@ -0,0 +1,29 @@ +// +// C++ Implementation: kxefilenewdialog +// +// Description: +// +// +// Author: Adam Charytoniuk <achary@poczta.onet.pl>, (C) 2003 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "kxefilenewdialog.h" + +#include <qcheckbox.h> +#include <qframe.h> + +KXEFileNewDialog::KXEFileNewDialog(QWidget* parent, const char* name) + : KXESpecProcInstrDialog(parent, name) +{ + m_pDontShowAgain->show(); + m_pHLine->show(); +} + + +KXEFileNewDialog::~KXEFileNewDialog() +{ +} + + diff --git a/part/kxefilenewdialog.h b/part/kxefilenewdialog.h new file mode 100644 index 0000000..20b3f1b --- /dev/null +++ b/part/kxefilenewdialog.h @@ -0,0 +1,31 @@ +// +// C++ Interface: kxefilenewdialog +// +// Description: +// +// +// Author: Adam Charytoniuk <achary@poczta.onet.pl>, (C) 2003 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#ifndef DLGFILENEW_H +#define DLGFILENEW_H + +#include "kxespecprocinstrdialog.h" + +/** +Dialog for File->New assistance. + +@author Adam Charytoniuk +*/ +class KXEFileNewDialog : public KXESpecProcInstrDialog +{ +public: + KXEFileNewDialog(QWidget* parent, const char* name=0); + + ~KXEFileNewDialog(); + +}; + +#endif diff --git a/part/kxenewfilesettings.cpp b/part/kxenewfilesettings.cpp new file mode 100644 index 0000000..fcd4562 --- /dev/null +++ b/part/kxenewfilesettings.cpp @@ -0,0 +1,207 @@ +/*************************************************************************** + kxenewfilesettings.cpp + ---------------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 "kxenewfilesettings.h" +#include "kxenewfilesettingspage.h" + +#include <klocale.h> +#include <kconfig.h> +#include <kdebug.h> + +#include <qframe.h> +#include <qlineedit.h> +#include <qcombobox.h> +#include <qbuttongroup.h> +#include <qradiobutton.h> + +#define CONF_ENTRY_NAME_DFLT_VERSION "Default version" +#define DFLT_VALUE_DFLT_VERSION "1.0" + +#define CONF_ENTRY_NAME_DFLT_ENCODING "Default encoding" +#define DFLT_VALUE_DFLT_ENCODING "UTF-8" + +#define CONF_ENTRY_NAME_DFLT_NEWFILE_CREAT_BEHAVIOUR "Default behaviour" +#define DFLT_VALUE_NEWFILE_CREAT_BEHAVIOUR UseDefaults + + +KXENewFileSettings::KXENewFileSettings( QObject * pParent, const char * pszName ) + : KXESettings( "New File Settings", pParent, pszName ), + m_strDfltVersion( DFLT_VALUE_DFLT_VERSION ), + m_strDfltEncoding( DFLT_VALUE_DFLT_ENCODING ), + m_enmNewFileCreaBehav( DFLT_VALUE_NEWFILE_CREAT_BEHAVIOUR ), + m_pDialogPage(0) +{ +} + + +void KXENewFileSettings::write( KConfig * pConfig ) const +{ + pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_VERSION, m_strDfltVersion ); + pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_ENCODING, m_strDfltEncoding ); + pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_NEWFILE_CREAT_BEHAVIOUR, m_enmNewFileCreaBehav ); +} + + +void KXENewFileSettings::read( const KConfig * pConfig ) +{ + m_strDfltVersion = pConfig->readEntry( CONF_ENTRY_NAME_DFLT_VERSION, DFLT_VALUE_DFLT_VERSION ); + m_strDfltEncoding = pConfig->readEntry( CONF_ENTRY_NAME_DFLT_ENCODING, DFLT_VALUE_DFLT_ENCODING ); + m_enmNewFileCreaBehav = static_cast<NewFileCreationBehaviour> ( pConfig->readNumEntry( CONF_ENTRY_NAME_DFLT_NEWFILE_CREAT_BEHAVIOUR, DFLT_VALUE_NEWFILE_CREAT_BEHAVIOUR ) ); +} + + +QString KXENewFileSettings::dialogPageName() const +{ + return i18n( "New Files" ); +} + +QString KXENewFileSettings::dialogPageHeader() const +{ + return i18n( "New File Settings" ); +} + +QString KXENewFileSettings::dialogPageIcon() const +{ + return "files"; +} + + +QWidget * KXENewFileSettings::dialogPage( QFrame * pParent ) +{ + + if ( ! m_pDialogPage ) + { + // create the page if necessary + m_pDialogPage = new KXENewFileSettingsPage( pParent, "new files config.dialog page" ); + + // and fill its widgets with the corresponding values + m_pDialogPage->m_pDfltEncoding->insertStringList( encodings() ); + updatePage(); + + connect( m_pDialogPage->m_pDfltVersion, SIGNAL(textChanged(const QString&)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pDfltEncoding, SIGNAL(activated(int)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pNewFileCreatBehav1, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pNewFileCreatBehav2, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pNewFileCreatBehav3, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + } + + return m_pDialogPage; +} + +void KXENewFileSettings::setFromPage() +{ + if ( m_pDialogPage ) + { + m_strDfltVersion = m_pDialogPage->m_pDfltVersion->text(); + m_strDfltEncoding = m_pDialogPage->m_pDfltEncoding->currentText(); + + if ( m_pDialogPage->m_pNewFileCreatBehav1->isChecked() ) + m_enmNewFileCreaBehav = CreateEmptyFile; + else if ( m_pDialogPage->m_pNewFileCreatBehav2->isChecked() ) + m_enmNewFileCreaBehav = CreateWithAssistance; + else if ( m_pDialogPage->m_pNewFileCreatBehav3->isChecked() ) + m_enmNewFileCreaBehav = UseDefaults; + } +} + +void KXENewFileSettings::updatePage() const +{ + if ( m_pDialogPage ) + { + m_pDialogPage->m_pDfltVersion->setText( m_strDfltVersion ); + m_pDialogPage->m_pDfltEncoding->setCurrentText( m_strDfltEncoding ); + + switch ( m_enmNewFileCreaBehav ) + { + case CreateEmptyFile: + m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav1 ) ); + break; + case CreateWithAssistance: + m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav2 ) ); + break; + case UseDefaults: + m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav3 ) ); + break; + default: + kdError() << "KXENewFileSettings::updatePage: unknown creation behavior" << endl; + } + } +} + +QStringList KXENewFileSettings::encodings() +{ + static QStringList lstEncs; + if ( lstEncs.empty() ) + { + lstEncs.append("UTF-8"); + lstEncs.append("ISO-8859-1"); + lstEncs.append("ISO-8859-2"); + lstEncs.append("ISO-8859-3"); + lstEncs.append("ISO-8859-4"); + lstEncs.append("ISO-8859-5"); + lstEncs.append("ISO-8859-6"); + lstEncs.append("ISO-8859-7"); + lstEncs.append("ISO-8859-8"); + lstEncs.append("ISO-8859-9"); + } + return lstEncs; +} + + +///////////////////////////////////////////////// +// function(s) to set this settings group data // +///////////////////////////////////////////////// + +void KXENewFileSettings::setNewFileCreaBehav( NewFileCreationBehaviour enmNewFileCreaBehav, KConfig * pConfig ) +{ + // if the data really has been changed + if ( m_enmNewFileCreaBehav != enmNewFileCreaBehav ) + { + // set this object's data to the new one given + m_enmNewFileCreaBehav = enmNewFileCreaBehav; + + // update the corresponding widget in the config.dialog page, if necessary + if ( m_pDialogPage ) + { + blockSignals( true ); + + switch ( enmNewFileCreaBehav ) + { + case CreateEmptyFile: + m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav1 ) ); + break; + case CreateWithAssistance: + m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav2 ) ); + break; + case UseDefaults: + m_pDialogPage->m_pNewFileCreatBehav->setButton( m_pDialogPage->m_pNewFileCreatBehav->id( m_pDialogPage->m_pNewFileCreatBehav3 ) ); + break; + default: + kdError() << "KXENewFileSettings::dialogPage: unknown creation behavior" << endl; + } + + blockSignals( false ); + } + + // store the new data (only the given one) to the given config file + setConfigGroup( pConfig ); + pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_NEWFILE_CREAT_BEHAVIOUR, m_enmNewFileCreaBehav ); + + // and inform everyone about the changing of our data + emit sigChanged(); + } +} diff --git a/part/kxenewfilesettings.h b/part/kxenewfilesettings.h new file mode 100644 index 0000000..b1203ec --- /dev/null +++ b/part/kxenewfilesettings.h @@ -0,0 +1,111 @@ +/*************************************************************************** + kxenewfilesettings.h + -------------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 KXENEWFILESETTINGS_H +#define KXENEWFILESETTINGS_H + +#include "kxesettings.h" + +class KXENewFileSettingsPage; + +/** + * This class represents the group of configuration settings for + * new files. + * + * @author Olaf Hartig + */ +class KXENewFileSettings : public KXESettings +{ + public: + + enum NewFileCreationBehaviour + { + CreateEmptyFile, + CreateWithAssistance, + UseDefaults + }; + + KXENewFileSettings( QObject * pParent = 0, const char * pszName = 0 ); + + // The following functions can be used to access this object's settings. + QString dfltVersion() const { return m_strDfltVersion; } + QString dfltEncoding() const { return m_strDfltEncoding; } + NewFileCreationBehaviour newFileCreaBehav() const { return m_enmNewFileCreaBehav; } + + /** + * Returns a list of all possible encodings. + */ + static QStringList encodings(); + + /** + * Sets this object's new file creation behavior to the given one, + * updates the corresponding widget (in the config.dialog page + * @ref m_pDialogPage), stores this value to the given config.file + * and emits the signal @ref KXESettings::sigChanged. + */ + void setNewFileCreaBehav( NewFileCreationBehaviour, KConfig * ); + + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageName() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageHeader() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageIcon() const; + /** + * Derived from @ref KXESettings + */ + virtual QWidget * dialogPage( QFrame * pParent ); + + protected: + + /** + * Derived from @ref KXESettings + */ + virtual void write( KConfig * ) const; + /** + * Derived from @ref KXESettings + */ + virtual void read( const KConfig * ); + /** + * Derived from @ref KXESettings + */ + virtual void setFromPage(); + /** + * Derived from @ref KXESettings + */ + virtual void updatePage() const; + + // the settings itself + QString m_strDfltVersion; + QString m_strDfltEncoding; + NewFileCreationBehaviour m_enmNewFileCreaBehav; + + /** + * the corresponding configuration dialog page + * It is created on demand by @ref dialogPage. + */ + KXENewFileSettingsPage * m_pDialogPage; + +}; + +#endif diff --git a/part/kxenewfilesettingspage.ui b/part/kxenewfilesettingspage.ui new file mode 100644 index 0000000..bf766e8 --- /dev/null +++ b/part/kxenewfilesettingspage.ui @@ -0,0 +1,176 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXENewFileSettingsPage</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KXENewFileSettingsPage</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>288</width> + <height>197</height> + </rect> + </property> + <property name="caption"> + <string>New File Settings Page</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblDfltVersion</cstring> + </property> + <property name="text"> + <string>XML &version:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pDfltVersion</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>XML version</b> +<br> +You can determine the default XML version for XML documents being created. This version is the default setting in wizard dialogs.<br> +Since there's only one XML version yet, you shouldn't change this value.</string> + </property> + </widget> + <widget class="QLineEdit"> + <property name="name"> + <cstring>m_pDfltVersion</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>XML version</b> +<br> +You can determine the default XML version for XML documents being created. This version is the default setting in wizard dialogs.<br> +Since there's only one XML version yet, you shouldn't change this value.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblDfltEncoding</cstring> + </property> + <property name="text"> + <string>Default &encoding:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pDfltEncoding</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Default encoding</b> +<br> +You can determine the default encoding for XML documents being created. This version is the default setting in wizard dialogs.</string> + </property> + </widget> + <widget class="QComboBox"> + <property name="name"> + <cstring>m_pDfltEncoding</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Default encoding</b> +<br> +You can determine the default encoding for XML documents being created. This version is the default setting in wizard dialogs.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QButtonGroup"> + <property name="name"> + <cstring>m_pNewFileCreatBehav</cstring> + </property> + <property name="title"> + <string>&Behavior on creating new files</string> + </property> + <property name="exclusive"> + <bool>true</bool> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Behavior on creating new files</b> +<br> +You can determine the behavior on creating new XML documents. Choose one of the following:<br> +<br> +<b><i>Start with new empty file</i></b><br> +Creates an empty XML document.<br> +<br> +<b><i>Start with file settings dialog assistance</i></b><br> +Opens a dialog to choose the XML version and encoding of the new document.<br> +<br> +<b><i>Start with new file with default settings</i></b><br> +Creates an XML document with the default XML version and default encoding selected above.</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>m_pNewFileCreatBehav1</cstring> + </property> + <property name="text"> + <string>Start with new empty file</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>m_pNewFileCreatBehav2</cstring> + </property> + <property name="text"> + <string>Start with file settings dialog assistance</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>m_pNewFileCreatBehav3</cstring> + </property> + <property name="text"> + <string>Start with new file with default settings</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </vbox> + </widget> + <spacer> + <property name="name"> + <cstring>spacer8</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxeprintsettings.cpp b/part/kxeprintsettings.cpp new file mode 100644 index 0000000..765102b --- /dev/null +++ b/part/kxeprintsettings.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + kxeprintsettings.cpp + -------------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 "kxeprintsettings.h" +#include "kxeprintsettingspage.h" + +#include <klocale.h> +#include <kconfig.h> +#include <kfontcombo.h> + +#include <qframe.h> +#include <qspinbox.h> +#include <qcheckbox.h> + +#define CONF_ENTRY_NAME_FONTFAMILY "Print font family" +#define DFLT_VALUE_FONTFAMILY "Courier" + +#define CONF_ENTRY_NAME_FONTSIZE "Print font size" +#define DFLT_VALUE_FONTSIZE 10 + +#define CONF_ENTRY_NAME_INDENT_STEPS "Print indentation" +#define DFLT_VALUE_INDENT_STEPS 2 + +#define CONF_ENTRY_NAME_WITH_FOOTER "Print has footer" +#define DFLT_VALUE_WITH_FOOTER true + +#define CONF_ENTRY_NAME_WITH_HEADER "Print has header" +#define DFLT_VALUE_WITH_HEADER true + + +KXEPrintSettings::KXEPrintSettings( QObject * pParent, const char * pszName ) + : KXESettings( "Print Settings", pParent, pszName ), + m_strFontFamily( DFLT_VALUE_FONTFAMILY ), + m_iFontSize( DFLT_VALUE_FONTSIZE ), + m_iIndentSteps( DFLT_VALUE_INDENT_STEPS ), + m_bWithHeader( DFLT_VALUE_WITH_FOOTER ), + m_bWithFooter( DFLT_VALUE_WITH_HEADER ), + m_pDialogPage(0) +{ +} + + +void KXEPrintSettings::write( KConfig * pConfig ) const +{ + pConfig->writeEntry( CONF_ENTRY_NAME_FONTFAMILY, m_strFontFamily ); + pConfig->writeEntry( CONF_ENTRY_NAME_FONTSIZE, m_iFontSize ); + pConfig->writeEntry( CONF_ENTRY_NAME_INDENT_STEPS, m_iIndentSteps ); + pConfig->writeEntry( CONF_ENTRY_NAME_WITH_FOOTER, m_bWithHeader ); + pConfig->writeEntry( CONF_ENTRY_NAME_WITH_HEADER, m_bWithFooter ); +} + + +void KXEPrintSettings::read( const KConfig * pConfig ) +{ + m_strFontFamily = pConfig->readEntry( CONF_ENTRY_NAME_FONTFAMILY, DFLT_VALUE_FONTFAMILY ); + m_iFontSize = pConfig->readNumEntry( CONF_ENTRY_NAME_FONTSIZE, DFLT_VALUE_FONTSIZE ); + m_iIndentSteps = pConfig->readNumEntry( CONF_ENTRY_NAME_INDENT_STEPS, DFLT_VALUE_INDENT_STEPS ); + m_bWithHeader = pConfig->readBoolEntry( CONF_ENTRY_NAME_WITH_FOOTER, DFLT_VALUE_WITH_FOOTER ); + m_bWithFooter = pConfig->readBoolEntry( CONF_ENTRY_NAME_WITH_HEADER, DFLT_VALUE_WITH_HEADER ); +} + +QString KXEPrintSettings::dialogPageName() const +{ + return i18n( "Printing" ); +} + +QString KXEPrintSettings::dialogPageHeader() const +{ + return i18n( "Print Settings" ); +} + +QString KXEPrintSettings::dialogPageIcon() const +{ + return "printer2"; +} + +QWidget * KXEPrintSettings::dialogPage( QFrame * pParent ) +{ + if ( ! m_pDialogPage ) + { + // create the page if necessary + m_pDialogPage = new KXEPrintSettingsPage( pParent, "printing config.dialog page" ); + + // and fill its widgets with the corresponding values + updatePage(); + + connect( m_pDialogPage->m_pFontFamily, SIGNAL(activated(int)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pFontSize, SIGNAL(valueChanged(int)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pIndentSteps, SIGNAL(valueChanged(int)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pWithHeader, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pWithFooter, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + } + + return m_pDialogPage; +} + + +void KXEPrintSettings::setFromPage() +{ + if ( m_pDialogPage ) + { + m_strFontFamily = m_pDialogPage->m_pFontFamily->currentText(); + m_iFontSize = m_pDialogPage->m_pFontSize->value(); + m_iIndentSteps = m_pDialogPage->m_pIndentSteps->value(); + m_bWithHeader = m_pDialogPage->m_pWithHeader->isChecked(); + m_bWithFooter = m_pDialogPage->m_pWithFooter->isChecked(); + } +} + +void KXEPrintSettings::updatePage() const +{ + if ( m_pDialogPage ) + { + m_pDialogPage->m_pFontFamily->setCurrentFont( m_strFontFamily ); + m_pDialogPage->m_pFontSize->setValue( m_iFontSize ); + m_pDialogPage->m_pIndentSteps->setValue( m_iIndentSteps ); + m_pDialogPage->m_pWithHeader->setChecked( m_bWithHeader ); + m_pDialogPage->m_pWithFooter->setChecked( m_bWithFooter ); + } +} diff --git a/part/kxeprintsettings.h b/part/kxeprintsettings.h new file mode 100644 index 0000000..fb833f6 --- /dev/null +++ b/part/kxeprintsettings.h @@ -0,0 +1,95 @@ +/*************************************************************************** + kxeprintsettings.h + ------------------ + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 KXEPRINTSETTINGS_H +#define KXEPRINTSETTINGS_H + +#include "kxesettings.h" + +class KXEPrintSettingsPage; + +/** + * This class represents the group of configuration settings for + * printing. + * + * @author Olaf Hartig + */ +class KXEPrintSettings : public KXESettings +{ + public: + + KXEPrintSettings( QObject * pParent = 0, const char * pszName = 0 ); + + // The following functions can be used to access this object's settings. + QString fontFamily() const { return m_strFontFamily; } + int fontSize() const { return m_iFontSize; } + int indentSteps() const { return m_iIndentSteps; } + bool hasHeader() const { return m_bWithHeader; } + bool hasFooter() const { return m_bWithFooter; } + + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageName() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageHeader() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageIcon() const; + /** + * Derived from @ref KXESettings + */ + virtual QWidget * dialogPage( QFrame * pParent ); + + protected: + + /** + * Derived from @ref KXESettings + */ + virtual void write( KConfig * ) const; + /** + * Derived from @ref KXESettings + */ + virtual void read( const KConfig * ); + /** + * Derived from @ref KXESettings + */ + virtual void setFromPage(); + /** + * Derived from @ref KXESettings + */ + virtual void updatePage() const; + + // the settings itself + QString m_strFontFamily; + int m_iFontSize; + int m_iIndentSteps; + bool m_bWithHeader; + bool m_bWithFooter; + + /** + * the corresponding configuration dialog page + * It is created on demand by @ref dialogPage. + */ + KXEPrintSettingsPage * m_pDialogPage; + +}; + +#endif diff --git a/part/kxeprintsettingspage.ui b/part/kxeprintsettingspage.ui new file mode 100644 index 0000000..a857413 --- /dev/null +++ b/part/kxeprintsettingspage.ui @@ -0,0 +1,228 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXEPrintSettingsPage</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KXEPrintSettingsPage</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>292</width> + <height>187</height> + </rect> + </property> + <property name="caption"> + <string>Print Settings Page</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblFontFamily</cstring> + </property> + <property name="frameShape"> + <enum>NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>Plain</enum> + </property> + <property name="text"> + <string>Font &family:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pFontFamily</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Font family</b> +<br> +Choose the font family you want to be used on printing your XML documents.</string> + </property> + </widget> + <widget class="KFontCombo"> + <property name="name"> + <cstring>m_pFontFamily</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Font family</b> +<br> +Choose the font family you want to be used on printing your XML documents.</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblFontSize</cstring> + </property> + <property name="text"> + <string>Font &size:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pFontSize</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Font size</b> +<br> +Choose the font size you want to be used on printing your XML documents.</string> + </property> + </widget> + <widget class="QSpinBox"> + <property name="name"> + <cstring>m_pFontSize</cstring> + </property> + <property name="suffix"> + <string>pt</string> + </property> + <property name="specialValueText"> + <string></string> + </property> + <property name="minValue"> + <number>6</number> + </property> + <property name="value"> + <number>10</number> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Font size</b> +<br> +Choose the font size you want to be used on printing your XML documents.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>31</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblIndentSteps</cstring> + </property> + <property name="text"> + <string>Element &indentation:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pIndentSteps</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Element indentation</b> +<br> +Choose the number of characters you want to be used for indenting childnodes on printing you XML documents.</string> + </property> + </widget> + <widget class="QSpinBox"> + <property name="name"> + <cstring>m_pIndentSteps</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Element indentation</b> +<br> +Choose the number of characters you want to be used for indenting childnodes on printing you XML documents.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>41</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pWithHeader</cstring> + </property> + <property name="text"> + <string>&Print header</string> + </property> + <property name="accel"> + <string>Alt+P</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Print header</b> +<br> +You can determine wether you want a header to be printed on every page when printing you XML documents or not.</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pWithFooter</cstring> + </property> + <property name="text"> + <string>P&rint footer</string> + </property> + <property name="accel"> + <string>Alt+R</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Print footer</b> +<br> +You can determine wether you want a footline to be printed on every page when printing you XML documents or not.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer10</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kfontcombo.h</includehint> + <includehint>klineedit.h</includehint> +</includehints> +</UI> diff --git a/part/kxeprocinstrdialog.cpp b/part/kxeprocinstrdialog.cpp new file mode 100644 index 0000000..7ddbf21 --- /dev/null +++ b/part/kxeprocinstrdialog.cpp @@ -0,0 +1,183 @@ +/*************************************************************************** + kxeprocinstrdialog.cpp - description + ------------------- + begin : Mit Apr 24 2002 + copyright : (C) 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 "kxeprocinstrdialog.h" + +#include <qlabel.h> +#include <qcombobox.h> +#include <qpushbutton.h> +#include <qtextedit.h> + +#include <klineedit.h> +#include <kdebug.h> +#include <klocale.h> +#include <kmessagebox.h> + +KXEProcInstrDialog::KXEProcInstrDialog( QWidget * pParent, const char * pszName, bool fModal, WFlags fl ) + : KXEProcInstrDialogBase( pParent, pszName, fModal, fl ) +{ + // signals and slots connections + connect( m_pBtnOK, SIGNAL( clicked() ), this, SLOT( slotAccept() ) ); + connect( m_pEditData, SIGNAL(textChanged()), this, SLOT(slotDataChanged()) ); + connect( m_pEditTarget, SIGNAL(textChanged(const QString &)), this, SLOT(slotTargetChanged(const QString &)) ); +} + + +void KXEProcInstrDialog::clearDialog() +{ + m_pEditTarget->clear(); + m_pEditData->clear(); +} + + +int KXEProcInstrDialog::exec( bool bEditExisting, bool bParentIsDocument ) +{ + if(bEditExisting) + { + m_pComboInsert->hide(); + m_pComboInsert->setDisabled(true); + m_pLblInsert->hide(); + m_pLblInsert->setDisabled(true); + + m_pEditTarget->setDisabled(true); + + m_pEditTarget->setText( m_strTarget ); + m_pEditData->setText( m_strData ); + } + else + { + if ( bParentIsDocument ) + { + m_pComboInsert->hide(); + m_pComboInsert->setDisabled(true); + m_pLblInsert->hide(); + m_pLblInsert->setDisabled(true); + } + m_pEditTarget->setEnabled(true); + clearDialog(); + } + + int iReturn = exec(); + if ( iReturn == Accepted ) + { + m_bAtTop = ( m_pComboInsert->currentItem() == 0 ); + m_strTarget = m_pEditTarget->text(); + m_strData = m_pEditData->text(); + } + + return iReturn; +} + +int KXEProcInstrDialog::exec() +{ + if ( m_pEditTarget->text().isEmpty() ) + m_pBtnOK->setEnabled(false); + else + m_pBtnOK->setEnabled(true); + + if ( m_pEditTarget->isEnabled() ) + m_pEditTarget->setFocus(); + else + m_pEditData->setFocus(); + + m_pBtnOK->setDefault(true); + + return KXEProcInstrDialogBase::exec(); +} + +void KXEProcInstrDialog::slotDataChanged() +{ + QString strMessage = checkData(m_pEditData->text()); + if(strMessage.isEmpty()) + strMessage = checkTarget(m_pEditTarget->text()); + + m_pTextLabelMessage->setText(strMessage); + + if ( m_pEditData->text().isEmpty() || + m_pEditTarget->text().isEmpty() || + (strMessage.length() > 0) + ) + m_pBtnOK->setDisabled(true); + else + m_pBtnOK->setEnabled(true); +} + +void KXEProcInstrDialog::slotTargetChanged(const QString &strNewTarget) +{ + QString strMessage = checkTarget(strNewTarget); + if(strMessage.isEmpty()) + strMessage = checkData(m_pEditData->text()); + + m_pTextLabelMessage->setText(strMessage); + + if ( m_pEditData->text().isEmpty() || + strNewTarget.isEmpty() || + (strMessage.length() > 0) + ) + m_pBtnOK->setDisabled(true); + else + m_pBtnOK->setEnabled(true); +} + +/** Called when user press OK button */ +void KXEProcInstrDialog::slotAccept() +{ + if(m_pEditTarget->text() == "xml") + { KMessageBox::sorry(this, i18n("Pleasse use menu item File -> Version and encoding for this processing instruction !")); + return; + } + + accept(); +} + +// Check, if XML proc. instr. target is OK +QString KXEProcInstrDialog::checkTarget(const QString strTarget) +{ + if(strTarget.length() == 0) + return ""; + + // Forbidden characters + QString strForbiddenChars("<>"); + for(unsigned int i = 0; i < strForbiddenChars.length(); i++) + { + QChar ch = strForbiddenChars[i]; + + if(strTarget.find(ch) >= 0) + return i18n("Target cannot contain character: %1 !").arg(ch); + } + + return ""; +} + +// Check, if XML proc. instr. data is OK +QString KXEProcInstrDialog::checkData(const QString strData) +{ + if(strData.length() == 0) + return ""; + + // Forbidden characters + QString strForbiddenChars("<>"); + for(unsigned int i = 0; i < strForbiddenChars.length(); i++) + { + QChar ch = strForbiddenChars[i]; + + if(strData.find(ch) >= 0) + return i18n("Contents cannot contain character: %1 !").arg(ch); + } + + return ""; +} diff --git a/part/kxeprocinstrdialog.h b/part/kxeprocinstrdialog.h new file mode 100644 index 0000000..5b4de2e --- /dev/null +++ b/part/kxeprocinstrdialog.h @@ -0,0 +1,87 @@ +/*************************************************************************** + kxeprocinstrdialog.h - description + -------------------- + begin : Mit Apr 24 2002 + copyright : (C) 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 KXEPROCINSTRDIALOG_H +#define KXEPROCINSTRDIALOG_H + +#include "kxeprocinstrdialogbase.h" + +class KXEProcInstrDialog : public KXEProcInstrDialogBase +{ + Q_OBJECT + + public: + KXEProcInstrDialog( QWidget * pParent = 0, const char * pszName = 0, bool fModal = true, WFlags fl = 0 ); + + const bool atTop() const { return m_bAtTop; } + const QString target() const { return m_strTarget; } + const QString data() const { return m_strData; } + + void setTarget(const QString strTarget) { m_strTarget = strTarget; } + void setData(const QString strData) { m_strData = strData; } + + public: + + /** + * To be used for inserting a proc.instruction as child + * of the given parent node. + * + * @return see @ref QDialog::exec + */ + int exec( bool, bool ); + + /** + * Clears the dialogs widgets. + */ + void clearDialog(); + + // check target + static QString checkTarget(const QString); + + // check data + static QString checkData(const QString); + + protected: + /** + * Don't use this function directly, it's for internal use only. + * Use one of the other @ref KXEProcInstrDialog::exec functions instead. + */ + int exec(); + + protected slots: + /** + * Called, when the data edit box is changed. + * Disables the OK button, if the editbox is empty. + */ + void slotDataChanged(); + + /** + * Called, when the target edit box is changed. + * Disables the OK button, if the editbox is empty. + */ + void slotTargetChanged(const QString &); + + /** Called when user press OK button */ + void slotAccept(); + + protected: + QString m_strTarget; + QString m_strData; + bool m_bAtTop; +}; + +#endif diff --git a/part/kxeprocinstrdialogbase.ui b/part/kxeprocinstrdialogbase.ui new file mode 100644 index 0000000..c77d10b --- /dev/null +++ b/part/kxeprocinstrdialogbase.ui @@ -0,0 +1,223 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXEProcInstrDialogBase</class> +<widget class="QDialog"> + <property name="name"> + <cstring>KXEProcInstrDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>367</width> + <height>244</height> + </rect> + </property> + <property name="caption"> + <string>Processing Instruction</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblTarget</cstring> + </property> + <property name="text"> + <string>&Target:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pEditTarget</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Target</b><br/> +Define the target of this processing instruction here.</string> + </property> + </widget> + <widget class="QLineEdit"> + <property name="name"> + <cstring>m_pEditTarget</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Target</b><br/> +Define the target of this processing instruction here.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>60</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblInsert</cstring> + </property> + <property name="text"> + <string>&Insert:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pComboInsert</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Insert</b> +<br/> +Choose, where to place this processing instruction in the parent elements list.</string> + </property> + </widget> + <widget class="QComboBox"> + <item> + <property name="text"> + <string>at bottom</string> + </property> + </item> + <item> + <property name="text"> + <string>at top</string> + </property> + </item> + <property name="name"> + <cstring>m_pComboInsert</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Insert</b> +<br/> +Choose, where to place this processing instruction in the parent elements list.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QTextEdit" row="1" column="0"> + <property name="name"> + <cstring>m_pEditData</cstring> + </property> + <property name="wordWrap"> + <enum>NoWrap</enum> + </property> + <property name="whatsThis" stdset="0"> + <string>Here you can enter the data (the instructions) of this XML processing instruction.</string> + </property> + </widget> + <widget class="QLayoutWidget" row="3" column="0"> + <property name="name"> + <cstring>Layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnOK</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string>Alt+O</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string>Alt+C</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </hbox> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>m_pTextLabelMessage</cstring> + </property> + <property name="paletteForegroundColor"> + <color> + <red>255</red> + <green>0</green> + <blue>0</blue> + </color> + </property> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>m_pBtnCancel</sender> + <signal>clicked()</signal> + <receiver>KXEProcInstrDialogBase</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>m_pEditTarget</tabstop> + <tabstop>m_pComboInsert</tabstop> + <tabstop>m_pEditData</tabstop> + <tabstop>m_pBtnOK</tabstop> + <tabstop>m_pBtnCancel</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxesearchdialog.cpp b/part/kxesearchdialog.cpp new file mode 100644 index 0000000..5830e96 --- /dev/null +++ b/part/kxesearchdialog.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + kxesearchdialog.cpp - description + ------------------- + begin : Tue Jul 10 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 "kxesearchdialog.h" + +#include <qpushbutton.h> + +KXESearchDialog::KXESearchDialog(QWidget *parent, const char *name, bool modal) + : KXESearchDialogBase(parent, name, modal) +{ + m_pPushButtonFind->setEnabled(false); + m_pEditSearchedString->setFocus(); + m_pPushButtonFind->setDefault(true); +} + +void KXESearchDialog::slotTextChanged(const QString& string) +{ + if ( string.isEmpty() ) + m_pPushButtonFind->setEnabled(false); + else + m_pPushButtonFind->setEnabled(true); + + toggleAcceptButton(); +} + +void KXESearchDialog::slotFindInChanged() +{ + toggleAcceptButton(); +} + +void KXESearchDialog::toggleAcceptButton() +{ + if ( (m_pCheckBoxElementNames->isChecked()) ||(m_pCheckBoxAttributeNames->isChecked()) || (m_pCheckBoxAttributeValues->isChecked()) || (m_pCheckBoxContents->isChecked()) ) + { + if ( m_pEditSearchedString->text().isEmpty() ) + m_pPushButtonFind->setEnabled(false); + else + m_pPushButtonFind->setEnabled(true); + } + else + m_pPushButtonFind->setEnabled(false); +} diff --git a/part/kxesearchdialog.h b/part/kxesearchdialog.h new file mode 100644 index 0000000..abe7f3d --- /dev/null +++ b/part/kxesearchdialog.h @@ -0,0 +1,57 @@ +/*************************************************************************** + kxesearchdialog.h - description + ----------------- + begin : Tue Jul 10 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 KXESEARCHDIALOG_H +#define KXESEARCHDIALOG_H + +#include "kxesearchdialogbase.h" + +#include <qlineedit.h> +#include <qcheckbox.h> + +/** + * Dialog for input information from user + * about searching in XML document + */ +// TODO add possibility to search backwards +class KXESearchDialog : public KXESearchDialogBase +{ + Q_OBJECT + + public: + KXESearchDialog( QWidget * pParent, const char * pszName = 0, bool bModal = true ); + + QString getSearchString() const { return m_pEditSearchedString->text(); } + bool getMatchCase() const { return m_pCheckBoxMatchCase->isChecked(); } + bool getInElementNames() const { return m_pCheckBoxElementNames->isChecked(); } + bool getInAttributeNames() const { return m_pCheckBoxAttributeNames->isChecked(); } + bool getInAttributeValues() const { return m_pCheckBoxAttributeValues->isChecked(); } + bool getInContents() const { return m_pCheckBoxContents->isChecked(); } + + protected: + /** Enables/Disables the "Find"-button. */ + void toggleAcceptButton(); + + protected slots: + /** Called when text in edit line is changed */ + virtual void slotTextChanged(const QString & ); + + /** Called on a change of the "find in" checkbuttons. */ + virtual void slotFindInChanged(); +}; + +#endif diff --git a/part/kxesearchdialogbase.ui b/part/kxesearchdialogbase.ui new file mode 100644 index 0000000..23be699 --- /dev/null +++ b/part/kxesearchdialogbase.ui @@ -0,0 +1,350 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXESearchDialogBase</class> +<comment>Dialog for input information from user +about searching in XML document</comment> +<author>Lumir Vanek</author> +<widget class="QDialog"> + <property name="name"> + <cstring>KXESearchDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>354</width> + <height>244</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>330</width> + <height>240</height> + </size> + </property> + <property name="sizeIncrement"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + <property name="caption"> + <string>Search</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLayoutWidget" row="0" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>Layout5</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pTextLabelSearchedString</cstring> + </property> + <property name="frameShape"> + <enum>MShape</enum> + </property> + <property name="frameShadow"> + <enum>MShadow</enum> + </property> + <property name="text"> + <string>&Search string:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pEditSearchedString</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Search string</b></br> +Here you can enter the string you want to search for in your XML document.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>Spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>262</width> + <height>0</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget class="QLineEdit" row="1" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>m_pEditSearchedString</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Search string</b></br> +Here you can enter the string you want to search for in your XML document.</string> + </property> + </widget> + <widget class="QLayoutWidget" row="4" column="0" rowspan="1" colspan="2"> + <property name="name"> + <cstring>layout13</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>Spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>154</width> + <height>16</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pPushButtonFind</cstring> + </property> + <property name="text"> + <string>&Find</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pPushButtonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + </widget> + </hbox> + </widget> + <spacer row="3" column="1"> + <property name="name"> + <cstring>Spacer9</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>131</height> + </size> + </property> + </spacer> + <widget class="QGroupBox" row="2" column="0" rowspan="2" colspan="1"> + <property name="name"> + <cstring>m_pGroupBoxSearchIn</cstring> + </property> + <property name="title"> + <string>Find &in</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Find in</b> +<br/> +Here you can choose the parts of your XML document that should be inspected during the search. +<br/> +These are +<br/> +<br/> +<b><i>Element names</i></b><br/> +<b><i>Attribute names</i></b><br/> +<b><i>Attribute values</i></b><br/> +<b><i>Content</i></b></string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pCheckBoxElementNames</cstring> + </property> + <property name="text"> + <string>Element names</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pCheckBoxAttributeNames</cstring> + </property> + <property name="text"> + <string>Attribute names</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pCheckBoxAttributeValues</cstring> + </property> + <property name="text"> + <string>Attribute values</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pCheckBoxContents</cstring> + </property> + <property name="text"> + <string>Content</string> + </property> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget" row="2" column="1"> + <property name="name"> + <cstring>layout23</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer19</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>18</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pCheckBoxMatchCase</cstring> + </property> + <property name="text"> + <string>&Match case</string> + </property> + <property name="accel"> + <string>Alt+M</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Match case</b><br/> +Check this for case sensitive search.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer20</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>19</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>m_pEditSearchedString</sender> + <signal>textChanged(const QString&)</signal> + <receiver>KXESearchDialogBase</receiver> + <slot>slotTextChanged(const QString&)</slot> + </connection> + <connection> + <sender>m_pPushButtonCancel</sender> + <signal>clicked()</signal> + <receiver>KXESearchDialogBase</receiver> + <slot>reject()</slot> + </connection> + <connection> + <sender>m_pPushButtonFind</sender> + <signal>clicked()</signal> + <receiver>KXESearchDialogBase</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>m_pCheckBoxElementNames</sender> + <signal>stateChanged(int)</signal> + <receiver>KXESearchDialogBase</receiver> + <slot>slotFindInChanged()</slot> + </connection> + <connection> + <sender>m_pCheckBoxAttributeNames</sender> + <signal>stateChanged(int)</signal> + <receiver>KXESearchDialogBase</receiver> + <slot>slotFindInChanged()</slot> + </connection> + <connection> + <sender>m_pCheckBoxAttributeValues</sender> + <signal>stateChanged(int)</signal> + <receiver>KXESearchDialogBase</receiver> + <slot>slotFindInChanged()</slot> + </connection> + <connection> + <sender>m_pCheckBoxContents</sender> + <signal>stateChanged(int)</signal> + <receiver>KXESearchDialogBase</receiver> + <slot>slotFindInChanged()</slot> + </connection> +</connections> +<tabstops> + <tabstop>m_pEditSearchedString</tabstop> + <tabstop>m_pCheckBoxElementNames</tabstop> + <tabstop>m_pCheckBoxAttributeNames</tabstop> + <tabstop>m_pCheckBoxAttributeValues</tabstop> + <tabstop>m_pCheckBoxContents</tabstop> + <tabstop>m_pCheckBoxMatchCase</tabstop> + <tabstop>m_pPushButtonFind</tabstop> + <tabstop>m_pPushButtonCancel</tabstop> +</tabstops> +<slots> + <slot access="protected">slotFindInChanged()</slot> + <slot access="protected">slotTextChanged(const QString &)</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxesettings.cpp b/part/kxesettings.cpp new file mode 100644 index 0000000..013e73f --- /dev/null +++ b/part/kxesettings.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + kxesettings.cpp + --------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 "kxesettings.h" + +#include <kconfig.h> + +KXESettings::KXESettings( const QString & strConfigGroup, QObject * pParent, const char * pszName ) + : QObject( pParent, pszName ), + m_bPageChanged( false ), + m_strConfigGroup( strConfigGroup ) +{ + connect( this, SIGNAL(sigDialogPageChanged()), this, SLOT(slotDialogPageChanged()) ); +} + +void KXESettings::setConfigGroup( KConfig * pConfig ) const +{ + pConfig->setGroup( m_strConfigGroup ); +} + +void KXESettings::store( KConfig * pConfig ) const +{ + setConfigGroup( pConfig ); + write( pConfig ); +} + +void KXESettings::restore( KConfig * pConfig ) +{ + setConfigGroup( pConfig ); + read( pConfig ); + + // update the corresponding config.dialog page + blockSignals( true ); // block this object's signals (especially sigDialogPageChanged) + updatePage(); + blockSignals( false ); // unblock the signals + + emit sigChanged(); +} + +void KXESettings::slotDialogPageChanged() +{ + m_bPageChanged = true; +} + +void KXESettings::apply() +{ + if ( m_bPageChanged ) + { + setFromPage(); + m_bPageChanged = false; + emit sigChanged(); + } +} diff --git a/part/kxesettings.h b/part/kxesettings.h new file mode 100644 index 0000000..804c63e --- /dev/null +++ b/part/kxesettings.h @@ -0,0 +1,175 @@ +/*************************************************************************** + kxesettings.h + ------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 KXESETTINGS_H +#define KXESETTINGS_H + +#include <qobject.h> + +class KConfig; +class QFrame; + +/** + * This is an abstract base class for classes representing a group, that stores + * several configuration settings and manages a corresponding page in the + * configuration dialog. + * + * @author Olaf Hartig + */ +class KXESettings : public QObject +{ + Q_OBJECT + + public: + + /** + * the constructor + * + * @param strConfigGroup the name of the corresponding group in the config file, + * it is copied to the member @ref m_strConfigGroup + */ + KXESettings( const QString & strConfigGroup, QObject * pParent = 0, const char * pszName = 0 ); + + /** + * Stores this settings to the given @ref KConfig object, by doing the + * following things: + * + * - set the config group by calling @ref setConfigGroup + * - write the data to the given @ref KConfig object by calling @ref write + * (which is implemented in the child class) + */ + void store( KConfig * ) const; + /** + * Restores the settings from the given @ref KConfig object, by doing + * following things: + * + * - set the config group by calling @ref setConfigGroup + * - read the data from the given @ref KConfig object by calling @ref read + * (which is implemented in the child class) + * - try to update the corresponding config.page by calling @ref updatePage + * (implemented in the child class) + * - emit the signal sigChanged + */ + void restore( KConfig * ); + /** + * If the data in the corresponding configuration dialog page has been + * changed (@ref m_bPageChanged), this data gets applied by the + * @ref setFromPage member function implemented in child classes, + * the flag @ref m_bPageChanged is reset (to false) and the signal + * sigChanged is emitted. + */ + void apply(); + + /** + * Override this function and return the name of the corresponding + * configuration dialog page. This is the name used in the list of + * pages in the configuration dialog. + * This name has to be internationalized. + */ + virtual QString dialogPageName() const = 0; + /** + * You can override this function and return a header line to + * be used for the corresponding configuration dialog page. + * If it's not overridden, the pages name is used (see + * @ref dialogPageName) + * This string has to be internationalized. + */ + virtual QString dialogPageHeader() const { return QString::null; } + /** + * Override this function and return the (file-)name of the icon + * to be used in the configuration dialog for the corresponding page. + */ + virtual QString dialogPageIcon() const = 0; + /** + * Override this function to create the corresponding configuration + * dialog page with the given parent and return it. + * Update the page's widgets (usually by using @ref updatePage). + * Connect the signal @ref sigDialogPageChanged to the page's + * data changed signal(s). + */ + virtual QWidget * dialogPage( QFrame * pParent ) = 0; + + + signals: + + /** + * This signal is always emitted when the settings change. + * It is emitted by @ref restore and @ref apply. + */ + void sigChanged(); + /** + * Emitted, when the data in the corresponding dialog page + * has been changed. + * Connect this signal to the page's changed signal in your + * child class in @ref dialogPage. + */ + void sigDialogPageChanged(); + + protected: + + /** + * Overide this function and write your settings to the given KConfig object. + * You mustn't change the config group. + */ + virtual void write( KConfig * ) const = 0; + /** + * Overide this function and read the settings from the given KConfig object. + * You mustn't change the config group. + */ + virtual void read( const KConfig * ) = 0; + /** + * Override this function to set this object's data to the data in the + * corresponding configuration dialog page, if a page has already been + * created (check this!). + */ + virtual void setFromPage() = 0; + /** + * Override this function to update the widgets in the corresponding + * configuration dialog page with the current data (from your child class + * object), if a page has already been created (check this!). + */ + virtual void updatePage() const = 0; + + /** + * Sets the config group of the given @ref KConfig object to + * this setting's config group (@ref m_strConfigGroup). + */ + void setConfigGroup( KConfig * ) const; + + /** + * This flag is set to true if the data in the corresponding configuration + * dialog's page has been changed but not applied yet. + */ + bool m_bPageChanged; + + protected slots: + + /** + * Sets the flag @ref m_bPageChanged to true. + */ + void slotDialogPageChanged(); + + private: + + /** + * name of the config group for this group of settings + */ + const QString m_strConfigGroup; + +}; + +#endif diff --git a/part/kxespecprocinstrdialog.cpp b/part/kxespecprocinstrdialog.cpp new file mode 100644 index 0000000..09f1224 --- /dev/null +++ b/part/kxespecprocinstrdialog.cpp @@ -0,0 +1,135 @@ +/*************************************************************************** + kxespecprocinstrdialog.cpp - description + -------------------------- + begin : Ne ?ec 6 2003 + copyright : (C) 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 "kxespecprocinstrdialog.h" + +#include "kxmleditorfactory.h" +#include "kxeconfiguration.h" +#include "kxenewfilesettings.h" + +#include <qstring.h> +#include <qcombobox.h> +#include <qlineedit.h> +#include <qpushbutton.h> +#include <qregexp.h> +#include <qframe.h> +#include <qcheckbox.h> + +#include <kdebug.h> + +KXESpecProcInstrDialog::KXESpecProcInstrDialog(QWidget *parent, const char *name ) + : KXESpecProcInstrDialogBase(parent,name) +{ + m_pComboBoxEncoding->insertStringList( KXMLEditorFactory::configuration()->newfile()->encodings() ); + + m_pLineEditVersion->setText("1.0"); + + m_pHLine->hide(); + m_pDontShowAgain->hide(); + + // signals and slots connections + connect( m_pBtnOK, SIGNAL( clicked() ), this, SLOT( slotAccept() ) ); +} + +KXESpecProcInstrDialog::~KXESpecProcInstrDialog() +{ +} + +void KXESpecProcInstrDialog::fillDialog( const QString strData ) +{ + QString strVersion; + QString strEncoding; + + int iStart, iEnd; + + // find version info + if((iStart = strData.find("version", 0)) >= 0) + { + // info about encoding found; + iStart += 7; // skip version + + // search " or ' after encoding + if((iStart = strData.find(QRegExp("[\"']"), iStart)) > 0) + { + QChar ch = strData[iStart]; + iStart++; // skip ch + if((iEnd = strData.find(ch, iStart)) > 0) + strVersion = strData.mid(iStart, iEnd - iStart); + } + } + else + strVersion = "1.0"; + + // find encoding info + if((iStart = strData.find("encoding", 0)) >= 0) + { + // info about encoding found; + iStart += 8; // skip encoding + + // search " or ' after encoding + if((iStart = strData.find(QRegExp("[\"']"), iStart)) > 0) + { + QChar ch = strData[iStart]; + iStart++; // skip ch + if((iEnd = strData.find(ch, iStart)) > 0) + strEncoding = strData.mid(iStart, iEnd - iStart); + } + } + else + strEncoding = "UTF-8"; + + + m_pLineEditVersion->setText(strVersion); + m_pComboBoxEncoding->setCurrentText(strEncoding); +} + +int KXESpecProcInstrDialog::exec() +{ + m_pBtnOK->setDefault(true); + + return KXESpecProcInstrDialogBase::exec(); +} + + +/** Called when user press OK button */ +void KXESpecProcInstrDialog::slotAccept() +{ + accept(); +} + + +/*! + Initializes content of dialog controls with specified values. + @param version XML file version + @param encoding encoding type for the XML file + */ +void KXESpecProcInstrDialog::fillDialog(const QString& version, const QString& encoding) +{ + + m_pLineEditVersion->setText(version); + m_pComboBoxEncoding->setCurrentText(encoding); +} + + +/*! + Returns content of the dialog as an string of format: '"version = '...' encoding = '...' ". + */ +QString KXESpecProcInstrDialog::getData() +{ + return QString("version = '")+m_pLineEditVersion->text()+ + "' encoding = '"+m_pComboBoxEncoding->currentText()+"' "; +} diff --git a/part/kxespecprocinstrdialog.h b/part/kxespecprocinstrdialog.h new file mode 100644 index 0000000..c78301f --- /dev/null +++ b/part/kxespecprocinstrdialog.h @@ -0,0 +1,54 @@ +/*************************************************************************** + kxespecprocinstrdialog.h - description + ------------------------ + begin : Ne ?ec 6 2003 + copyright : (C) 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 KXESPECPROCINSTRDIALOG_H +#define KXESPECPROCINSTRDIALOG_H + +#include "kxespecprocinstrdialogbase.h" + +#include <qwidget.h> + +/** + *@author Lumir Vanek + */ + +class KXESpecProcInstrDialog : public KXESpecProcInstrDialogBase +{ + Q_OBJECT + +public: + KXESpecProcInstrDialog(QWidget *parent=0, const char *name=0); + ~KXESpecProcInstrDialog(); + + QString getData(); + + /** Initialize dialog from given target and data string */ + void fillDialog(const QString&, const QString&); + + /** Initialize dialog from given data string */ + void fillDialog(const QString); + + int exec(); + +protected slots: + + /** Called when user press OK button */ + void slotAccept(); + +}; + +#endif diff --git a/part/kxespecprocinstrdialogbase.ui b/part/kxespecprocinstrdialogbase.ui new file mode 100644 index 0000000..1bcbb25 --- /dev/null +++ b/part/kxespecprocinstrdialogbase.ui @@ -0,0 +1,191 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXESpecProcInstrDialogBase</class> +<author>Lumir Vanek</author> +<widget class="QDialog"> + <property name="name"> + <cstring>KXESpecProcInstrDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>216</width> + <height>191</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>5</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>Special processing instruction</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>m_pTextLabel1</cstring> + </property> + <property name="text"> + <string>XML &version:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pLineEditVersion</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>XML version</b><br/> +You can determine the XML version for XML document.</string> + </property> + </widget> + <widget class="QLineEdit" row="1" column="0"> + <property name="name"> + <cstring>m_pLineEditVersion</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>XML version</b><br/> +You can determine the XML version for XML document.</string> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>m_pTextLabel2</cstring> + </property> + <property name="text"> + <string>&Encoding:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pComboBoxEncoding</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Encoding</b><br/> +You can determine the encoding used while saving this XML document.</string> + </property> + </widget> + <widget class="QComboBox" row="3" column="0"> + <property name="name"> + <cstring>m_pComboBoxEncoding</cstring> + </property> + <property name="editable"> + <bool>true</bool> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Encoding</b><br/> +You can determine the encoding used while saving this XML document.</string> + </property> + </widget> + <widget class="QLayoutWidget" row="4" column="0"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pDontShowAgain</cstring> + </property> + <property name="text"> + <string>Do not show this dialog again</string> + </property> + <property name="accel"> + <string>Ctrl+T</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Do not show this dialog again</b><br/> +If you select this option, your choice will be remembered. Next time you create a new file, you won't be disturbed by this dialog box.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QFrame" row="5" column="0"> + <property name="name"> + <cstring>m_pHLine</cstring> + </property> + <property name="frameShape"> + <enum>HLine</enum> + </property> + <property name="frameShadow"> + <enum>Raised</enum> + </property> + </widget> + <widget class="QLayoutWidget" row="6" column="0"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnOK</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>m_pBtnCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="autoDefault"> + <bool>false</bool> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>m_pBtnCancel</sender> + <signal>clicked()</signal> + <receiver>KXESpecProcInstrDialogBase</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>m_pLineEditVersion</tabstop> + <tabstop>m_pComboBoxEncoding</tabstop> + <tabstop>m_pDontShowAgain</tabstop> + <tabstop>m_pBtnOK</tabstop> + <tabstop>m_pBtnCancel</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxesyntaxhighlighter.cpp b/part/kxesyntaxhighlighter.cpp new file mode 100644 index 0000000..c783077 --- /dev/null +++ b/part/kxesyntaxhighlighter.cpp @@ -0,0 +1,257 @@ +/*************************************************************************** + kxesyntaxhighlighter.cpp - XML Syntax highlighter + ------------------- + begin : Ne pro 14 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : lvanek.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 "kxesyntaxhighlighter.h" + +#include <iostream> + +#include <qcolor.h> +#include <qregexp.h> +#include <qstring.h> +#include <qstringlist.h> + +#include <ktextedit.h> + +// Regular expressions for parsing XML borrowed from: +// http://www.cs.sfu.ca/~cameron/REX.html + +KXESyntaxHighlighter::KXESyntaxHighlighter(QTextEdit *textEdit) + : QSyntaxHighlighter(textEdit) +{ + m_clrDefaultText.setRgb(0, 0, 0); + m_clrElementName.setRgb(128, 0, 0); + m_clrAttributeName.setRgb(0, 255, 255); + m_clrAttributeValue.setRgb(0, 255, 0); + m_clrXmlSyntaxChar.setRgb(0, 0, 128); + m_clrComment.setRgb(128, 128, 128); + m_clrSyntaxError.setRgb(255, 0, 0); +} + +KXESyntaxHighlighter::~KXESyntaxHighlighter() +{ +} + + +int KXESyntaxHighlighter::highlightParagraph(const QString& text, int endStateOfLastPara) +{ + //first I format the given line to default so any remaining highlighting is removed (Qt does not do it by itself) + setFormat(0 , text.length(), QColor(0, 0, 0)); + + int iBracketNesting = 0; + m_eParserState = parsingNone; + int pos; + unsigned int i = 0; + + if(endStateOfLastPara == 1) + { + QRegExp patternComment("[^-]*-([^-][^-]*-)*->"); // search end of comment + pos=patternComment.search(text, i); + + if(pos >= 0) // end comment found ? + { + int l = patternComment.matchedLength(); + + setFormat(0, l - 3, m_clrComment); + setFormat(l - 3, 3, m_clrXmlSyntaxChar ); + i += l; // skip comment + } + else + { + setFormat(0, text.length(), m_clrComment); + return 1; // return 1 to signify "in comment" + } + } + + for(; i < text.length() - 1; i++) + { + switch(text[i]) + { + case '<': + iBracketNesting++; + + if(iBracketNesting == 1) + { setFormat( i, 1, m_clrXmlSyntaxChar ); + m_eParserState = expectElementNameOrSlash; + } + else + setFormat( i, 1, m_clrSyntaxError ); // wrong bracket nesting + + break; + + case '>': + iBracketNesting--; + + if(iBracketNesting == 0) + setFormat( i, 1, m_clrXmlSyntaxChar ); + else + setFormat( i, 1, m_clrSyntaxError ); // wrong bracket nesting + + m_eParserState = parsingNone; + + break; + + case '/': + + if(m_eParserState == expectElementNameOrSlash) + { + m_eParserState = expectElementName; + setFormat( i, 1, m_clrXmlSyntaxChar ); + } + else + { + if(m_eParserState == expectAtttributeOrEndOfElement) + setFormat( i, 1, m_clrXmlSyntaxChar ); + else + processDefaultText(i, text); + } + + break; + + case '=': + if(m_eParserState == expectEqual) + { + m_eParserState = expectAttributeValue; + setFormat( i, 1, m_clrXmlSyntaxChar ); + } + else + { + processDefaultText(i, text); + } + break; + + case '\"': + + if(m_eParserState == expectAttributeValue) + { + QRegExp patternAttribute("\"[^<\"]*\"|'[^<']*'"); // search attribute value + pos=patternAttribute.search(text, i); + + if(pos == (int) i) // attribute value found ? + { + int l = patternAttribute.matchedLength(); + + setFormat(i, 1, m_clrXmlSyntaxChar ); + setFormat(i+1, l - 2, m_clrAttributeValue); + setFormat(i+l-1, 1, m_clrXmlSyntaxChar ); + + i += l - 1; // skip attribute value + m_eParserState = expectAtttributeOrEndOfElement; + } + else + processDefaultText(i, text); + } + else + processDefaultText(i, text); + + break; + + case '!': + if(m_eParserState == expectElementNameOrSlash) + { + QRegExp patternComment("<!--[^-]*-([^-][^-]*-)*->"); // search comment + pos=patternComment.search(text, i-1); + + if(pos == (int) i-1) // comment found ? + { + int l = patternComment.matchedLength(); + + setFormat(pos, 4, m_clrXmlSyntaxChar); + setFormat(pos + 4, l - 7, m_clrComment); + setFormat(l - 3, 3, m_clrXmlSyntaxChar); + i += l - 2; // skip comment + m_eParserState = parsingNone; + iBracketNesting--; + } + else + { // Try find multiline comment + QRegExp patternCommentStart("<!--"); // search comment start + pos=patternCommentStart.search(text, i-1); + + if(pos == (int)i-1) // comment found ? + { + setFormat(i, 3, m_clrXmlSyntaxChar ); + setFormat(i + 3, text.length() - i - 3, m_clrComment); + return 1; // return 1 to signify "in comment" + } + else + processDefaultText(i, text); + } + } + else + processDefaultText(i, text); + + break; + + default: + int iLenght = processDefaultText(i, text); + if(iLenght > 0) + i += iLenght - 1; + break; + } + } + + return 0; +} + +int KXESyntaxHighlighter::processDefaultText(int i, const QString& text) +{ + int l = 0; // length of matched text + + switch(m_eParserState) + { + case expectElementNameOrSlash: + case expectElementName: + { + QRegExp patternName("([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*"); // search element name + int pos=patternName.search(text, i); + + if(pos == i) // found ? + { + l = patternName.matchedLength(); + + setFormat(pos, l, m_clrElementName); + m_eParserState = expectAtttributeOrEndOfElement; + } + else + setFormat( i, 1, m_clrDefaultText ); + } + break; + + case expectAtttributeOrEndOfElement: + { + QRegExp patternName("([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*"); // search attribute name + int pos=patternName.search(text, i); + + if(pos == i) // found ? + { + l = patternName.matchedLength(); + + setFormat(pos, l, m_clrAttributeName); + m_eParserState = expectEqual; + } + else + setFormat( i, 1, m_clrDefaultText ); + } + break; + + default: + setFormat( i, 1, m_clrDefaultText ); + break; + } + return l; +} + diff --git a/part/kxesyntaxhighlighter.h b/part/kxesyntaxhighlighter.h new file mode 100644 index 0000000..b6d8868 --- /dev/null +++ b/part/kxesyntaxhighlighter.h @@ -0,0 +1,80 @@ +/*************************************************************************** + kxesyntaxhighlighter.h - XML Syntax highlighter + ------------------- + begin : Ne pro 14 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : lvanek.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 KXESYNTAXHIGHLIGHTER_H +#define KXESYNTAXHIGHLIGHTER_H + +#include <qsyntaxhighlighter.h> + +class QTextEdit; + +/**XML Syntax highlighter + *@author Lumir Vanek + */ + +class KXESyntaxHighlighter : public QSyntaxHighlighter +{ +public: + KXESyntaxHighlighter(QTextEdit *); + ~KXESyntaxHighlighter(); + + int highlightParagraph(const QString &text, int endStateOfLastPara); + + void setColorDefaultText(const QColor color) { m_clrDefaultText = color; } + void setColorElementNames(const QColor color) { m_clrElementName = color; } + void setColorAttributeNames(const QColor color) { m_clrAttributeName = color; } + void setColorAttributeValues(const QColor color) { m_clrAttributeValue = color; } + void setColorXmlSyntaxChars(const QColor color) { m_clrXmlSyntaxChar = color; } + void setColorComments(const QColor color) { m_clrComment = color; } + void setColorSyntaxError(const QColor color) { m_clrSyntaxError = color; } + + const QColor colorDefaultText() const { return m_clrDefaultText; } + const QColor colorElementNames() const { return m_clrElementName; } + const QColor colorAttributeNames() const { return m_clrAttributeName; } + const QColor colorAttributeValues() const { return m_clrAttributeValue; } + const QColor colorXmlSyntaxChars() const { return m_clrXmlSyntaxChar; } + const QColor colorComments() const { return m_clrComment; } + const QColor colorSyntaxError() const { return m_clrSyntaxError; } + +protected: + int processDefaultText(int, const QString&); + +protected: + + QColor m_clrDefaultText; + QColor m_clrElementName; + QColor m_clrAttributeName; + QColor m_clrAttributeValue; + QColor m_clrXmlSyntaxChar; // < > = " + QColor m_clrComment; + QColor m_clrSyntaxError; + + // states for parsing XML + enum ParserState + { + parsingNone = 0, + expectElementNameOrSlash, + expectElementName, + expectAtttributeOrEndOfElement, + expectEqual, + expectAttributeValue + }; + + ParserState m_eParserState; +}; + +#endif diff --git a/part/kxetexteditordialog.cpp b/part/kxetexteditordialog.cpp new file mode 100644 index 0000000..d4b35b8 --- /dev/null +++ b/part/kxetexteditordialog.cpp @@ -0,0 +1,120 @@ +/*************************************************************************** + kxetexteditordialog.cpp - description + ------------------- + begin : Ne pro 14 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : lvanek.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 "kxetexteditordialog.h" + +#include "kxmleditorfactory.h" +#include "kxeconfiguration.h" +#include "kxetextviewsettings.h" + +#include <qdom.h> +#include <qpushbutton.h> + +#include <kmessagebox.h> +#include <ktextedit.h> +#include <klocale.h> +#include <kdebug.h> + +KXETextEditorDialog::KXETextEditorDialog(QWidget *parent, const char *name) + : KXETextEditorDialogBase(parent,name) +{ + m_pSyntaxHighlighter = new KXESyntaxHighlighter(m_pTextEditor); + + connect( m_pTextEditor, SIGNAL(textChanged()), this, SLOT(slotTextChanged()) ); + + // Apply current configuration + slotTextViewSettingsChanged(); + // and make sure to be informed about its changes. + connect( KXMLEditorFactory::configuration()->textview(), SIGNAL(sigChanged()), this, SLOT(slotTextViewSettingsChanged()) ); +} + +KXETextEditorDialog::~KXETextEditorDialog() +{ + delete m_pSyntaxHighlighter; +} + +void KXETextEditorDialog::slotTextChanged() +{ + if ( m_pTextEditor->text().isEmpty()) + m_pButtonOk->setEnabled(false); + else + m_pButtonOk->setEnabled(true); +} + +void KXETextEditorDialog::slotValidate() +{ + validateXml(true); +} + +void KXETextEditorDialog::accept() +{ + if(validateXml(false)) + KXETextEditorDialogBase::accept(); +} + +bool KXETextEditorDialog::validateXml(bool bInfoIfOK) +{ + QString strXML = "<root>" + editorText() + "</root>"; + + // create XML documemt from text + QString strErrorMsg; + int iErrorLine, iErrorColumn; + QDomDocument doc; + + if(!doc.setContent(strXML, true, &strErrorMsg, &iErrorLine, &iErrorColumn) ) + { kdDebug() << "KXETextEditorDialog::validateXml: Failed parsing the file." << endl; + + KMessageBox::error(this, + i18n("%1 in line %2, column %3").arg(strErrorMsg).arg(iErrorLine).arg(iErrorColumn), + i18n("Parsing error !")); + + + m_pTextEditor->setCursorPosition(iErrorLine - 1, iErrorColumn - 1); + + return false; + } + + // check if root item already exists + if(!doc.firstChild().firstChild().isElement()) + { KMessageBox::sorry(this, i18n("You are changed root element to another node type, while editing !")); + return false; + } + + if(bInfoIfOK) + KMessageBox::information(this, i18n("OK")); + + return true; +} + +void KXETextEditorDialog::slotTextViewSettingsChanged() +{ + m_pSyntaxHighlighter->setColorDefaultText( KXMLEditorFactory::configuration()->textview()->colorDfltText() ); + m_pSyntaxHighlighter->setColorElementNames( KXMLEditorFactory::configuration()->textview()->colorElemNames() ); + m_pSyntaxHighlighter->setColorAttributeNames( KXMLEditorFactory::configuration()->textview()->colorAttrNames() ); + m_pSyntaxHighlighter->setColorAttributeValues( KXMLEditorFactory::configuration()->textview()->colorAttrValues() ); + m_pSyntaxHighlighter->setColorXmlSyntaxChars( KXMLEditorFactory::configuration()->textview()->colorSyntaxChars() ); + m_pSyntaxHighlighter->setColorComments( KXMLEditorFactory::configuration()->textview()->colorComments() ); + m_pSyntaxHighlighter->setColorSyntaxError( KXMLEditorFactory::configuration()->textview()->colorErrors() ); + + if(KXMLEditorFactory::configuration()->textview()->isWrapOn()) + { + m_pTextEditor->setHScrollBarMode(QScrollView::AlwaysOff); + m_pTextEditor->setWordWrap(QTextEdit::WidgetWidth); + } + + m_pSyntaxHighlighter->rehighlight(); +} diff --git a/part/kxetexteditordialog.h b/part/kxetexteditordialog.h new file mode 100644 index 0000000..8d17be2 --- /dev/null +++ b/part/kxetexteditordialog.h @@ -0,0 +1,68 @@ +/*************************************************************************** + kxetexteditordialog.h - description + ------------------- + begin : Ne pro 14 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : lvanek.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 KXETEXTEDITORDIALOG_H +#define KXETEXTEDITORDIALOG_H + +#include <qwidget.h> +#include <qstring.h> +#include <qsyntaxhighlighter.h> + +#include <ktextedit.h> + +#include "kxetexteditordialogbase.h" +#include "kxesyntaxhighlighter.h" + +/**Dialog for editing raw XML as text + *@author Lumir Vanek + */ + +class KXETextEditorDialog : public KXETextEditorDialogBase +{ + Q_OBJECT +public: + KXETextEditorDialog(QWidget *parent=0, const char *name=0); + ~KXETextEditorDialog(); + + QString editorText() const { return m_pTextEditor->text(); } + void setEditorText(const QString strText) { m_pTextEditor->setText(strText); } + +public slots: + + /** + * Changes syntax highlighting colors. + */ + void slotTextViewSettingsChanged(); + +protected: + bool validateXml(bool); + +protected slots: + // fired, when user press Validate button + virtual void slotValidate(); + + // fired, when user change text editor contents + void slotTextChanged(); + + // fired, when user press OK button + virtual void accept(); + +private: + KXESyntaxHighlighter *m_pSyntaxHighlighter; +}; + +#endif diff --git a/part/kxetexteditordialogbase.ui b/part/kxetexteditordialogbase.ui new file mode 100644 index 0000000..0f454b9 --- /dev/null +++ b/part/kxetexteditordialogbase.ui @@ -0,0 +1,154 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXETextEditorDialogBase</class> +<comment>Dialog for editing XML node as raw text</comment> +<author>Lumir Vanek</author> +<widget class="QDialog"> + <property name="name"> + <cstring>KXETextEditorDialogBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>511</width> + <height>318</height> + </rect> + </property> + <property name="caption"> + <string>Edit XML as raw text</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KTextEdit" row="0" column="0" rowspan="1" colspan="4"> + <property name="name"> + <cstring>m_pTextEditor</cstring> + </property> + <property name="font"> + <font> + <family>Courier</family> + </font> + </property> + <property name="vScrollBarMode"> + <enum>AlwaysOn</enum> + </property> + <property name="hScrollBarMode"> + <enum>Auto</enum> + </property> + <property name="textFormat"> + <enum>PlainText</enum> + </property> + <property name="wordWrap"> + <enum>NoWrap</enum> + </property> + <property name="autoFormatting"> + <set>AutoAll</set> + </property> + <property name="whatsThis" stdset="0"> + <string>You can edit your XML document as raw text in this editor.</string> + </property> + </widget> + <widget class="QPushButton" row="1" column="2"> + <property name="name"> + <cstring>m_pButtonOk</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="accel"> + <string>Alt+O</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton" row="1" column="3"> + <property name="name"> + <cstring>m_pButtonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="accel"> + <string>Alt+C</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton" row="1" column="0"> + <property name="name"> + <cstring>m_pButtonValidate</cstring> + </property> + <property name="text"> + <string>&Validate</string> + </property> + <property name="accel"> + <string>Alt+V</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Validate</b><br/> +Press this button, if you want your XML document in the above editor to be validated.</string> + </property> + </widget> + <spacer row="1" column="1"> + <property name="name"> + <cstring>Horizontal Spacing2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>160</width> + <height>20</height> + </size> + </property> + </spacer> + </grid> +</widget> +<connections> + <connection> + <sender>m_pButtonOk</sender> + <signal>clicked()</signal> + <receiver>KXETextEditorDialogBase</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>m_pButtonCancel</sender> + <signal>clicked()</signal> + <receiver>KXETextEditorDialogBase</receiver> + <slot>reject()</slot> + </connection> + <connection> + <sender>m_pButtonValidate</sender> + <signal>clicked()</signal> + <receiver>KXETextEditorDialogBase</receiver> + <slot>slotValidate()</slot> + </connection> +</connections> +<tabstops> + <tabstop>m_pTextEditor</tabstop> + <tabstop>m_pButtonValidate</tabstop> +</tabstops> +<slots> + <slot access="protected">slotValidate()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>ktextedit.h</includehint> +</includehints> +</UI> diff --git a/part/kxetextviewsettings.cpp b/part/kxetextviewsettings.cpp new file mode 100644 index 0000000..7ed6ac6 --- /dev/null +++ b/part/kxetextviewsettings.cpp @@ -0,0 +1,173 @@ +/*************************************************************************** + kxetextviewsettings.cpp + ---------------------- + begin : Tue Dec 23 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 "kxetextviewsettings.h" +#include "kxetextviewsettingspage.h" + +#include <klocale.h> +#include <kconfig.h> +#include <kdebug.h> +#include <kcolorbutton.h> +#include <qcheckbox.h> + +#include <qframe.h> +#include <qspinbox.h> + +#define CONF_ENTRY_NAME_COLOR_DEFAULT_TEXT "DefaultText" +#define DFLT_VALUE_COLOR_DEFAULT_TEXT QColor( "#000000" ) + +#define CONF_ENTRY_NAME_COLOR_ELEMENT_NAMES "ElementNames" +#define DFLT_VALUE_COLOR_ELEMENT_NAMES QColor( "#800000" ) + +#define CONF_ENTRY_NAME_COLOR_ATTR_NAMES "AttributeNames" +#define DFLT_VALUE_COLOR_ATTR_NAMES QColor( "#00ffff" ) + +#define CONF_ENTRY_NAME_COLOR_ATTR_VALUES "AttributeValues" +#define DFLT_VALUE_COLOR_ATTR_VALUES QColor( "#00ff00" ) + +#define CONF_ENTRY_NAME_COLOR_SYNTAX_CHARS "SyntaxChars" +#define DFLT_VALUE_COLOR_SYNTAX_CHARS QColor( "#000080" ) + +#define CONF_ENTRY_NAME_COLOR_COMENTS "Comments" +#define DFLT_VALUE_COLOR_COMENTS QColor( "#808080" ) + +#define CONF_ENTRY_NAME_COLOR_ERRORS "SyntaxError" +#define DFLT_VALUE_COLOR_ERRORS QColor( "#ff0000" ) + +#define CONF_ENTRY_NAME_INDENT_STEPS "XML indentation" +#define DFLT_VALUE_INDENT_STEPS 2 + +#define CONF_ENTRY_WRAP_ON "Text Wrap On" +#define DFLT_VALUE_WRAP_ON false + +KXETextViewSettings::KXETextViewSettings( QObject * pParent, const char * pszName ) + : KXESettings( "Text editor", pParent, pszName ), + m_colorDfltText( DFLT_VALUE_COLOR_DEFAULT_TEXT ), + m_colorElemNames( DFLT_VALUE_COLOR_ELEMENT_NAMES ), + m_colorAttrNames( DFLT_VALUE_COLOR_ATTR_NAMES ), + m_colorAttrValues( DFLT_VALUE_COLOR_ATTR_VALUES ), + m_colorSyntaxChars( DFLT_VALUE_COLOR_SYNTAX_CHARS ), + m_colorComments( DFLT_VALUE_COLOR_COMENTS ), + m_colorErrors( DFLT_VALUE_COLOR_ERRORS ), + m_iIndentSteps( DFLT_VALUE_INDENT_STEPS ), + m_bWrapOn(DFLT_VALUE_WRAP_ON), + m_pDialogPage(0) + +{ +} + + +void KXETextViewSettings::write( KConfig * pConfig ) const +{ + pConfig->writeEntry( CONF_ENTRY_NAME_COLOR_DEFAULT_TEXT, m_colorDfltText ); + pConfig->writeEntry( CONF_ENTRY_NAME_COLOR_ELEMENT_NAMES, m_colorElemNames ); + pConfig->writeEntry( CONF_ENTRY_NAME_COLOR_ATTR_NAMES, m_colorAttrNames ); + pConfig->writeEntry( CONF_ENTRY_NAME_COLOR_ATTR_VALUES, m_colorAttrValues ); + pConfig->writeEntry( CONF_ENTRY_NAME_COLOR_SYNTAX_CHARS, m_colorSyntaxChars ); + pConfig->writeEntry( CONF_ENTRY_NAME_COLOR_COMENTS, m_colorComments ); + pConfig->writeEntry( CONF_ENTRY_NAME_COLOR_ERRORS, m_colorErrors ); + pConfig->writeEntry( CONF_ENTRY_NAME_INDENT_STEPS, m_iIndentSteps ); + pConfig->writeEntry( CONF_ENTRY_WRAP_ON, m_bWrapOn ); +} + + +void KXETextViewSettings::read( const KConfig * pConfig ) +{ + m_colorDfltText = pConfig->readColorEntry( CONF_ENTRY_NAME_COLOR_DEFAULT_TEXT, & DFLT_VALUE_COLOR_DEFAULT_TEXT ); + m_colorElemNames = pConfig->readColorEntry( CONF_ENTRY_NAME_COLOR_ELEMENT_NAMES, & DFLT_VALUE_COLOR_ELEMENT_NAMES ); + m_colorAttrNames = pConfig->readColorEntry( CONF_ENTRY_NAME_COLOR_ATTR_NAMES, & DFLT_VALUE_COLOR_ATTR_NAMES ); + m_colorAttrValues = pConfig->readColorEntry( CONF_ENTRY_NAME_COLOR_ATTR_VALUES, & DFLT_VALUE_COLOR_ATTR_VALUES ); + m_colorSyntaxChars = pConfig->readColorEntry( CONF_ENTRY_NAME_COLOR_SYNTAX_CHARS, & DFLT_VALUE_COLOR_SYNTAX_CHARS ); + m_colorComments = pConfig->readColorEntry( CONF_ENTRY_NAME_COLOR_COMENTS, & DFLT_VALUE_COLOR_COMENTS ); + m_colorErrors = pConfig->readColorEntry( CONF_ENTRY_NAME_COLOR_ERRORS, &DFLT_VALUE_COLOR_ERRORS ); + m_iIndentSteps = pConfig->readNumEntry( CONF_ENTRY_NAME_INDENT_STEPS, DFLT_VALUE_INDENT_STEPS ); + m_bWrapOn = pConfig->readNumEntry( CONF_ENTRY_WRAP_ON, DFLT_VALUE_WRAP_ON ); +} + + +QString KXETextViewSettings::dialogPageName() const +{ + return i18n( "Text view" ); +} + +QString KXETextViewSettings::dialogPageHeader() const +{ + return i18n( "Text view properties" ); +} + +QString KXETextViewSettings::dialogPageIcon() const +{ + return "colorize"; +} + + +QWidget * KXETextViewSettings::dialogPage( QFrame * pParent ) +{ + if ( ! m_pDialogPage ) + { + // create the page if necessary + m_pDialogPage = new KXETextViewSettingsPage( pParent, "text view config.dialog page" ); + + // and fill its widgets with the corresponding values + updatePage(); + + connect( m_pDialogPage->m_pColorDfltText, SIGNAL(changed(const QColor&)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pColorElemNames, SIGNAL(changed(const QColor&)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pColorAttrNames, SIGNAL(changed(const QColor&)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pColorAttrValues, SIGNAL(changed(const QColor&)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pColorSyntaxChars, SIGNAL(changed(const QColor&)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pColorComments, SIGNAL(changed(const QColor&)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pColorErrors, SIGNAL(changed(const QColor&)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pIndentSteps, SIGNAL(valueChanged(int)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pCheckBoxWrapOn, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + } + + return m_pDialogPage; +} + + +void KXETextViewSettings::setFromPage() +{ + if ( m_pDialogPage ) + { + m_colorDfltText = m_pDialogPage->m_pColorDfltText->color(); + m_colorElemNames = m_pDialogPage->m_pColorElemNames->color(); + m_colorAttrNames = m_pDialogPage->m_pColorAttrNames->color(); + m_colorAttrValues = m_pDialogPage->m_pColorAttrValues->color(); + m_colorSyntaxChars = m_pDialogPage->m_pColorSyntaxChars->color(); + m_colorComments = m_pDialogPage->m_pColorComments->color(); + m_colorErrors = m_pDialogPage->m_pColorErrors->color(); + m_iIndentSteps = m_pDialogPage->m_pIndentSteps->value(); + m_bWrapOn = m_pDialogPage->m_pCheckBoxWrapOn->isChecked(); + } +} + +void KXETextViewSettings::updatePage() const +{ + if ( m_pDialogPage ) + { + m_pDialogPage->m_pColorDfltText->setColor( m_colorDfltText ); + m_pDialogPage->m_pColorElemNames->setColor( m_colorElemNames ); + m_pDialogPage->m_pColorAttrNames->setColor( m_colorAttrNames ); + m_pDialogPage->m_pColorAttrValues->setColor( m_colorAttrValues ); + m_pDialogPage->m_pColorSyntaxChars->setColor( m_colorSyntaxChars ); + m_pDialogPage->m_pColorComments->setColor( m_colorComments ); + m_pDialogPage->m_pColorErrors->setColor( m_colorErrors ); + m_pDialogPage->m_pIndentSteps->setValue( m_iIndentSteps ); + m_pDialogPage->m_pCheckBoxWrapOn->setChecked( m_bWrapOn ); + } +} diff --git a/part/kxetextviewsettings.h b/part/kxetextviewsettings.h new file mode 100644 index 0000000..117282a --- /dev/null +++ b/part/kxetextviewsettings.h @@ -0,0 +1,105 @@ +/*************************************************************************** + kxetextviewsettings.h + -------------------- + begin : Tue Dec 23 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 KXETEXTVIEWSETTINGS_H +#define KXETEXTVIEWSETTINGS_H + +#include "kxesettings.h" + +#include <qcolor.h> + +class KXETextViewSettingsPage; + +/** + * This class represents the group of configuration settings for + * the text view. + * + * @author Olaf Hartig + */ +class KXETextViewSettings : public KXESettings +{ + public: + + KXETextViewSettings( QObject * pParent = 0, const char * pszName = 0 ); + + // The following functions can be used to access this object's settings. + const QColor & colorDfltText() const { return m_colorDfltText; } + const QColor & colorElemNames() const { return m_colorElemNames; } + const QColor & colorAttrNames() const { return m_colorAttrNames; } + const QColor & colorAttrValues() const { return m_colorAttrValues; } + const QColor & colorSyntaxChars() const { return m_colorSyntaxChars; } + const QColor & colorComments() const { return m_colorComments; } + const QColor & colorErrors() const { return m_colorErrors; } + int indentSteps() const { return m_iIndentSteps; } + bool isWrapOn() const { return m_bWrapOn; } + + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageName() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageHeader() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageIcon() const; + /** + * Derived from @ref KXESettings + */ + virtual QWidget * dialogPage( QFrame * pParent ); + + protected: + + /** + * Derived from @ref KXESettings + */ + virtual void write( KConfig * ) const; + /** + * Derived from @ref KXESettings + */ + virtual void read( const KConfig * ); + /** + * Derived from @ref KXESettings + */ + virtual void setFromPage(); + /** + * Derived from @ref KXESettings + */ + virtual void updatePage() const; + + // the settings itself + QColor m_colorDfltText; + QColor m_colorElemNames; + QColor m_colorAttrNames; + QColor m_colorAttrValues; + QColor m_colorSyntaxChars; + QColor m_colorComments; + QColor m_colorErrors; + int m_iIndentSteps; + bool m_bWrapOn; + + /** + * the corresponding configuration dialog page + * It is created on demand by @ref dialogPage. + */ + KXETextViewSettingsPage * m_pDialogPage; + +}; + +#endif diff --git a/part/kxetextviewsettingspage.ui b/part/kxetextviewsettingspage.ui new file mode 100644 index 0000000..f82c830 --- /dev/null +++ b/part/kxetextviewsettingspage.ui @@ -0,0 +1,266 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXETextViewSettingsPage</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KXETextViewSettingsPage</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>254</width> + <height>370</height> + </rect> + </property> + <property name="caption"> + <string>Text view settings</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>m_pBoxSyntaxHL</cstring> + </property> + <property name="title"> + <string>Syntax highlighting</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Syntax highlightning</b> +<br> +You can define the colors to be used, when showing your XML documents as raw text.</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>m_pLblColorDfltText</cstring> + </property> + <property name="text"> + <string>Default &Text:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pColorDfltText</cstring> + </property> + </widget> + <widget class="KColorButton" row="4" column="1"> + <property name="name"> + <cstring>m_pColorSyntaxChars</cstring> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>m_pLblColorElemNames</cstring> + </property> + <property name="text"> + <string>&Element names:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pColorElemNames</cstring> + </property> + </widget> + <widget class="KColorButton" row="5" column="1"> + <property name="name"> + <cstring>m_pColorComments</cstring> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="6" column="0"> + <property name="name"> + <cstring>m_pLblColorErrors</cstring> + </property> + <property name="text"> + <string>Syntax E&rrors:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pColorErrors</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>m_pLblColorAttrValues</cstring> + </property> + <property name="text"> + <string>Attribute &values:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pColorAttrValues</cstring> + </property> + </widget> + <widget class="KColorButton" row="1" column="1"> + <property name="name"> + <cstring>m_pColorElemNames</cstring> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>m_pLblColorComments</cstring> + </property> + <property name="text"> + <string>Co&mments:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pColorComments</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>m_pLblColorAttrNames</cstring> + </property> + <property name="text"> + <string>Attribute &names:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pColorAttrNames</cstring> + </property> + </widget> + <widget class="KColorButton" row="0" column="1"> + <property name="name"> + <cstring>m_pColorDfltText</cstring> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="KColorButton" row="2" column="1"> + <property name="name"> + <cstring>m_pColorAttrNames</cstring> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>m_pLblColorSyntaxChars</cstring> + </property> + <property name="text"> + <string>&Syntax characters:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pColorSyntaxChars</cstring> + </property> + </widget> + <widget class="KColorButton" row="3" column="1"> + <property name="name"> + <cstring>m_pColorAttrValues</cstring> + </property> + <property name="text"> + <string></string> + </property> + </widget> + <widget class="KColorButton" row="6" column="1"> + <property name="name"> + <cstring>m_pColorErrors</cstring> + </property> + <property name="text"> + <string></string> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>layout2</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblIndentSteps</cstring> + </property> + <property name="text"> + <string>Element &indentation:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pIndentSteps</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Element indentation</b> +<br> +You can choose the number of characters you want to be used for indenting childnodes, when showing your XML documents as raw text.</string> + </property> + </widget> + <widget class="QSpinBox"> + <property name="name"> + <cstring>m_pIndentSteps</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Element indentation</b> +<br> +You can choose the number of characters you want to be used for indenting childnodes, when showing your XML documents as raw text.</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>16</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <spacer row="3" column="0"> + <property name="name"> + <cstring>spacer8</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="QCheckBox" row="2" column="0"> + <property name="name"> + <cstring>m_pCheckBoxWrapOn</cstring> + </property> + <property name="text"> + <string>&Wrap, instead of Hrz. Scroll bar</string> + </property> + <property name="accel"> + <string>Alt+W</string> + </property> + </widget> + </grid> +</widget> +<tabstops> + <tabstop>m_pColorDfltText</tabstop> + <tabstop>m_pColorElemNames</tabstop> + <tabstop>m_pColorAttrNames</tabstop> + <tabstop>m_pColorAttrValues</tabstop> + <tabstop>m_pColorSyntaxChars</tabstop> + <tabstop>m_pColorComments</tabstop> + <tabstop>m_pColorErrors</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxetreeviewsettings.cpp b/part/kxetreeviewsettings.cpp new file mode 100644 index 0000000..fc59634 --- /dev/null +++ b/part/kxetreeviewsettings.cpp @@ -0,0 +1,166 @@ +/*************************************************************************** + kxetreeviewsettings.cpp + ----------------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 "kxetreeviewsettings.h" +#include "kxetreeviewsettingspage.h" + +#include <klocale.h> +#include <kconfig.h> +#include <kdebug.h> + +#include <qframe.h> +#include <qcheckbox.h> +#include <qspinbox.h> +#include <qbuttongroup.h> +#include <qradiobutton.h> + +#define CONF_ENTRY_NAME_ITEMS_ON_DEMAND "Create items on demand" +#define DFLT_VALUE_ITEMS_ON_DEMAND true + +#define CONF_ENTRY_NAME_DFLT_EXP_LEVEL "Expand to level" +#define DFLT_VALUE_DFLT_EXP_LEVEL 5 + +#define CONF_ENTRY_NAME_DECORATE_ROOT "Root decorated" +#define DFLT_VALUE_DECORATE_ROOT false + +#define CONF_ENTRY_NAME_ENABLE_DRAG "Enable Dragging" +#define DFLT_VALUE_ENABLE_DRAG true + +#define CONF_ENTRY_NAME_ENABLE_DROP "Enable Dropping" +#define DFLT_VALUE_ENABLE_DROP true + +#define CONF_ENTRY_NAME_ELEM_DISPL_MODE "Element display mode" +#define DFLT_VALUE_ELEM_DISPL_MODE NoAttributes + + +KXETreeViewSettings::KXETreeViewSettings( QObject * pParent, const char * pszName ) + : KXESettings( "Tree View", pParent, pszName ), + m_bCreateItemsOnDemand( DFLT_VALUE_ITEMS_ON_DEMAND ), + m_iDfltExpLevel( DFLT_VALUE_DFLT_EXP_LEVEL ), + m_bDecorateRoot( DFLT_VALUE_DECORATE_ROOT ), + m_bEnableDragging( DFLT_VALUE_ENABLE_DRAG ), + m_bEnableDropping( DFLT_VALUE_ENABLE_DROP ), + m_enmElemDisplMode( DFLT_VALUE_ELEM_DISPL_MODE ), + m_pDialogPage(0) +{ +} + +void KXETreeViewSettings::write( KConfig * pConfig ) const +{ + pConfig->writeEntry( CONF_ENTRY_NAME_ITEMS_ON_DEMAND, m_bCreateItemsOnDemand ); + pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_EXP_LEVEL, m_iDfltExpLevel ); + pConfig->writeEntry( CONF_ENTRY_NAME_DECORATE_ROOT, m_bDecorateRoot ); + pConfig->writeEntry( CONF_ENTRY_NAME_ENABLE_DRAG, m_bEnableDragging ); + pConfig->writeEntry( CONF_ENTRY_NAME_ENABLE_DROP, m_bEnableDropping ); + pConfig->writeEntry( CONF_ENTRY_NAME_ELEM_DISPL_MODE, m_enmElemDisplMode ); +} + +void KXETreeViewSettings::read( const KConfig * pConfig ) +{ + m_bCreateItemsOnDemand = pConfig->readBoolEntry( CONF_ENTRY_NAME_ITEMS_ON_DEMAND, DFLT_VALUE_ITEMS_ON_DEMAND ); + m_iDfltExpLevel = pConfig->readNumEntry( CONF_ENTRY_NAME_DFLT_EXP_LEVEL, DFLT_VALUE_DFLT_EXP_LEVEL ); + m_bDecorateRoot = pConfig->readBoolEntry( CONF_ENTRY_NAME_DECORATE_ROOT, DFLT_VALUE_DECORATE_ROOT ); + m_bEnableDragging = pConfig->readBoolEntry( CONF_ENTRY_NAME_ENABLE_DRAG, DFLT_VALUE_ENABLE_DRAG ); + m_bEnableDropping = pConfig->readBoolEntry( CONF_ENTRY_NAME_ENABLE_DROP, DFLT_VALUE_ENABLE_DROP ); + m_enmElemDisplMode = static_cast<AttributeVisibility> ( pConfig->readNumEntry( CONF_ENTRY_NAME_ELEM_DISPL_MODE, DFLT_VALUE_ELEM_DISPL_MODE ) ); +} + +QString KXETreeViewSettings::dialogPageName() const +{ + return i18n( "Tree View" ); +} + +QString KXETreeViewSettings::dialogPageHeader() const +{ + return i18n( "Tree view properties" ); +} + +QString KXETreeViewSettings::dialogPageIcon() const +{ + return "view_tree"; +} + + +QWidget * KXETreeViewSettings::dialogPage( QFrame * pParent ) +{ + if ( ! m_pDialogPage ) + { + // create the page if necessary + m_pDialogPage = new KXETreeViewSettingsPage( pParent, "tree view config.dialog page" ); + + // and fill its widgets with the corresponding values + updatePage(); + + connect( m_pDialogPage->m_pCreateItemsOnDemand, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pDecorateRoot, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pDfltExpLevel, SIGNAL(valueChanged(int)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pEnableDrag, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pEnableDrop, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pElemDisplMode1, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pElemDisplMode2, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + connect( m_pDialogPage->m_pElemDisplMode3, SIGNAL(toggled(bool)), this, SIGNAL(sigDialogPageChanged()) ); + } + + return m_pDialogPage; +} + + +void KXETreeViewSettings::setFromPage() +{ + if ( m_pDialogPage ) + { + m_bCreateItemsOnDemand = m_pDialogPage->m_pCreateItemsOnDemand->isChecked(); + m_bDecorateRoot = m_pDialogPage->m_pDecorateRoot->isChecked(); + m_iDfltExpLevel = m_pDialogPage->m_pDfltExpLevel->value(); + m_bEnableDragging = m_pDialogPage->m_pEnableDrag->isChecked(); + m_bEnableDropping = m_pDialogPage->m_pEnableDrop->isChecked(); + + if ( m_pDialogPage->m_pElemDisplMode1->isChecked() ) + m_enmElemDisplMode = NoAttributes; + else if ( m_pDialogPage->m_pElemDisplMode2->isChecked() ) + m_enmElemDisplMode = NamesOnly; + else if ( m_pDialogPage->m_pElemDisplMode3->isChecked() ) + m_enmElemDisplMode = NamesAndValues; + } +} + +void KXETreeViewSettings::updatePage() const +{ + if ( m_pDialogPage ) + { + m_pDialogPage->m_pCreateItemsOnDemand->setChecked( m_bCreateItemsOnDemand ); + m_pDialogPage->m_pDecorateRoot->setChecked( m_bDecorateRoot ); + m_pDialogPage->m_pDfltExpLevel->setValue( m_iDfltExpLevel ); + m_pDialogPage->m_pEnableDrag->setChecked( m_bEnableDragging ); + m_pDialogPage->m_pEnableDrop->setChecked( m_bEnableDropping ); + + switch ( m_enmElemDisplMode ) + { + case NoAttributes: + m_pDialogPage->m_pElemDisplMode->setButton( m_pDialogPage->m_pElemDisplMode->id( m_pDialogPage->m_pElemDisplMode1 ) ); + break; + case NamesOnly: + m_pDialogPage->m_pElemDisplMode->setButton( m_pDialogPage->m_pElemDisplMode->id( m_pDialogPage->m_pElemDisplMode2 ) ); + break; + case NamesAndValues: + m_pDialogPage->m_pElemDisplMode->setButton( m_pDialogPage->m_pElemDisplMode->id( m_pDialogPage->m_pElemDisplMode3 ) ); + break; + default: + kdError() << "KXETreeViewSettings::updatePage: unknown element display mode" << endl; + } + } +} diff --git a/part/kxetreeviewsettings.h b/part/kxetreeviewsettings.h new file mode 100644 index 0000000..403a0bb --- /dev/null +++ b/part/kxetreeviewsettings.h @@ -0,0 +1,103 @@ +/*************************************************************************** + kxetreeviewsettings.h + --------------------- + begin : Tue Dec 02 2003 + copyright : (C) 2003 by The KXMLEditor Team + email : hartig@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 KXETREEVIEWSETTINGS_H +#define KXETREEVIEWSETTINGS_H + +#include "kxesettings.h" + +class KXETreeViewSettingsPage; + +/** + * This class represents the group of configuration settings for the + * tree view. + * + * @author Olaf Hartig + */ +class KXETreeViewSettings : public KXESettings +{ + public: + + enum AttributeVisibility + { + NoAttributes, + NamesOnly, + NamesAndValues + }; + + KXETreeViewSettings( QObject * pParent = 0, const char * pszName = 0 ); + + // The following functions can be used to access this object's settings. + bool createItemsOnDemand() const { return m_bCreateItemsOnDemand; } + int dfltExpLevel() const { return m_iDfltExpLevel; } + bool decorateRoot() const { return m_bDecorateRoot; } + bool enableDragging() const { return m_bEnableDragging; } + bool enableDropping() const { return m_bEnableDropping; } + AttributeVisibility elemDisplMode() const { return m_enmElemDisplMode; } + + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageName() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageHeader() const; + /** + * Derived from @ref KXESettings + */ + virtual QString dialogPageIcon() const; + /** + * Derived from @ref KXESettings + */ + virtual QWidget * dialogPage( QFrame * pParent ); + + protected: + + /** + * Derived from @ref KXESettings + */ + virtual void write( KConfig * ) const; + /** + * Derived from @ref KXESettings + */ + virtual void read( const KConfig * ); + /** + * Derived from @ref KXESettings + */ + virtual void setFromPage(); + /** + * Derived from @ref KXESettings + */ + virtual void updatePage() const; + + // the settings itself + bool m_bCreateItemsOnDemand; + int m_iDfltExpLevel; + bool m_bDecorateRoot; + bool m_bEnableDragging; + bool m_bEnableDropping; + AttributeVisibility m_enmElemDisplMode; + + /** + * the corresponding configuration dialog page + * It is created on demand by @ref dialogPage. + */ + KXETreeViewSettingsPage * m_pDialogPage; +}; + +#endif diff --git a/part/kxetreeviewsettingspage.ui b/part/kxetreeviewsettingspage.ui new file mode 100644 index 0000000..8cce39b --- /dev/null +++ b/part/kxetreeviewsettingspage.ui @@ -0,0 +1,226 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>KXETreeViewSettingsPage</class> +<widget class="QWidget"> + <property name="name"> + <cstring>KXETreeViewSettingsPage</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>218</width> + <height>325</height> + </rect> + </property> + <property name="caption"> + <string>Tree View Settings Page</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pCreateItemsOnDemand</cstring> + </property> + <property name="text"> + <string>Create items &on demand</string> + </property> + <property name="accel"> + <string>Alt+O</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Create items on demand</b> +<br> +You can determine when to create the tree view items. +Wether they are created on demand, which means their creation is postponed until +their grandparent item is opened, or all items are created while opening the XML +file. +<br> +Creating items on demand saves time and memory while opening very big, deep nested XML documents.</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pDecorateRoot</cstring> + </property> + <property name="text"> + <string>Set &root element decorated</string> + </property> + <property name="accel"> + <string>Alt+R</string> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Set root element decorated</b> +<br> +You can determine wether the tree view item corresponding to the XML document's root element should have a decoration or not. +<br> +A decoration is a + or - icon, with which the item can be opened or closed to show or hide its childitems.</string> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>m_pLblDfltExpLevel</cstring> + </property> + <property name="text"> + <string>Default &expand level:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>m_pDfltExpLevel</cstring> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Default expand level</b> +<br> +You can determine up to which level the tree view items should be opened (showing their childitems) when opening a document.</string> + </property> + </widget> + <widget class="QSpinBox"> + <property name="name"> + <cstring>m_pDfltExpLevel</cstring> + </property> + <property name="value"> + <number>5</number> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Default expand level</b> +<br> +You can determine up to which level the tree view items should be opened (showing their childitems) when opening a document.</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>m_pBoxDnD</cstring> + </property> + <property name="title"> + <string>Drag and drop</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pEnableDrag</cstring> + </property> + <property name="text"> + <string>Enable dra&gging</string> + </property> + <property name="accel"> + <string>Alt+G</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Enable dragging</b> +<br> +You can determine wether dragging items (and their corresponding XML nodes) from the tree view is enabled or disabled.</string> + </property> + </widget> + <widget class="QCheckBox"> + <property name="name"> + <cstring>m_pEnableDrop</cstring> + </property> + <property name="text"> + <string>Enable dro&pping</string> + </property> + <property name="accel"> + <string>Alt+P</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <property name="tristate"> + <bool>false</bool> + </property> + <property name="whatsThis" stdset="0"> + <string><b>Enable dropping</b> +<br> +You can determine wether dropping XML nodes to the tree view is enabled or disabled.</string> + </property> + </widget> + </vbox> + </widget> + <widget class="QButtonGroup"> + <property name="name"> + <cstring>m_pElemDisplMode</cstring> + </property> + <property name="title"> + <string>&Show ...</string> + </property> + <property name="whatsThis" stdset="0"> + <string>You can determine which information about XML element's attributes you want to see in the tree view. Choose between:<br> +<br> +<b><i>no attributes</i></b><br> +no information about attributes at all<br> +<br> +<b><i>attribute names only</i></b><br> +the attributes' names are shown<br> +<br> +<b><i>attribute names & values</i></b><br> +the attributes' names and the corresponding values are shown</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QRadioButton"> + <property name="name"> + <cstring>m_pElemDisplMode1</cstring> + </property> + <property name="text"> + <string>No attributes</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>m_pElemDisplMode2</cstring> + </property> + <property name="text"> + <string>Attribute names only</string> + </property> + </widget> + <widget class="QRadioButton"> + <property name="name"> + <cstring>m_pElemDisplMode3</cstring> + </property> + <property name="text"> + <string>Attribute names && values</string> + </property> + </widget> + </vbox> + </widget> + <spacer> + <property name="name"> + <cstring>spacer7</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/part/kxmleditorabout.h b/part/kxmleditorabout.h new file mode 100644 index 0000000..67478f0 --- /dev/null +++ b/part/kxmleditorabout.h @@ -0,0 +1,50 @@ +/*************************************************************************** + kxmleditorabout.h - description + ------------------- + begin : Mon Sep 24 2001 + copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team + email : OleBowle@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KXMLEDITORABOUT_H +#define KXMLEDITORABOUT_H + +#include <kaboutdata.h> +#include <klocale.h> + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +static const char *description = I18N_NOOP("KXML Editor is an utility to display and edit XML files"); + +class KXMLEditorAboutData : public KAboutData +{ + public: + KXMLEditorAboutData() + : KAboutData( "kxmleditor", + I18N_NOOP("KXML Editor"), + VERSION, + description, + KAboutData::License_GPL, + "(c) 2001-2004, The KXML Editor Developers", + 0, + "http://kxmleditor.sourceforge.net", + "lvanek@users.sourceforge.net" ) + { + addAuthor("Lumir Vanek", I18N_NOOP("Developer and maintainer"), "lvanek@users.sourceforge.net", "http://www.valachnet.cz/lvanek"); + addAuthor("Olaf Hartig", I18N_NOOP("Developer"), "hartig@users.sourceforge.net"); + addAuthor("Adam Charytoniuk", I18N_NOOP("Developer"), "a_charytoniuk@users.sourceforge.net"); + } +}; + +#endif diff --git a/part/kxmleditorfactory.cpp b/part/kxmleditorfactory.cpp new file mode 100644 index 0000000..40819db --- /dev/null +++ b/part/kxmleditorfactory.cpp @@ -0,0 +1,104 @@ +/*************************************************************************** + kxmleditorfactory.cpp - description + ------------------- + begin : Wed Sep 19 2001 + copyright : (C) 2001, 2002, 2003 byThe KXMLEditor Team + email : OleBowle@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kxmleditorfactory.h" +#include "kxmleditorpart.h" +#include "kxmleditorabout.h" +#include "kxeconfiguration.h" +#include "kxedocument.h" + +#include <kinstance.h> +#include <kdebug.h> + +extern "C" +{ + void * init_libkxmleditorpart() + { + return new KXMLEditorFactory; + } +} + +KInstance * KXMLEditorFactory::s_instance = 0L; +KXEConfiguration * KXMLEditorFactory::s_pKXEConfig = 0L; + +KXMLEditorFactory::KXMLEditorFactory( QObject * pParent, const char * pszName ) + : KParts::Factory(pParent,pszName) +{ +} + +KXMLEditorFactory::~KXMLEditorFactory() +{ + if ( s_pKXEConfig ) + delete s_pKXEConfig; + + s_pKXEConfig = 0L; + + if (s_instance) + delete s_instance; + + s_instance = 0L; +} + +KParts::Part * KXMLEditorFactory::createPartObject( QWidget * pParentWidget, const char * pszWidgetName, QObject * pParent, const char * pszName, const char * pszClassName, const QStringList & ) +{ + // eliminating compiler warnings + pParent = pParent; + pszName = pszName; + + KParts::Part * pPart=0L; + KXEDocument* pDocument=0L; + if ( QCString(pszClassName) == "KParts::ReadOnlyPart" ) + { + pDocument = new KXEDocument(); + pPart = new KXMLEditorPart( false, pDocument, pParentWidget, pszWidgetName ); + kdDebug() << "KXMLEditorFactory::createPartObject: read only KXMLEditorPart created" << endl; + } + else if ( (QCString(pszClassName) == "KParts::ReadWritePart") || + (QCString(pszClassName) == "KXMLEditorPart") ) + { + pDocument = new KXEDocument(); + pPart = new KXMLEditorPart( true, pDocument, pParentWidget, pszWidgetName ); + kdDebug() << "KXMLEditorFactory::createPartObject: read/write KXMLEditorPart created" << endl; + } + else + { + kdError() << "KXMLEditorFactory::createPartObject: classname isn't KParts::ReadOnlyPart nor KParts::ReadWritePart." << endl; + return 0L; + } + + + emit objectCreated( pPart ); + + return pPart; +} + +KInstance * KXMLEditorFactory::instance() +{ + if ( ! s_instance ) + { + s_instance = new KInstance( new KXMLEditorAboutData() ); + } + return s_instance; +} + +KXEConfiguration * KXMLEditorFactory::configuration() +{ + if ( ! s_pKXEConfig ) + s_pKXEConfig = new KXEConfiguration(); + + return s_pKXEConfig; +} diff --git a/part/kxmleditorfactory.h b/part/kxmleditorfactory.h new file mode 100644 index 0000000..b2c5e15 --- /dev/null +++ b/part/kxmleditorfactory.h @@ -0,0 +1,55 @@ +/*************************************************************************** + kxmleditorfactory.h - description + ------------------- + begin : Wed Sep 19 2001 + copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team + email : OleBowle@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KXMLEDITORFACTORY_H +#define KXMLEDITORFACTORY_H + +#include <kparts/factory.h> + +class KInstance; +class KXEConfiguration; +/** + @brief Factory for creating our parts. +*/ +class KXMLEditorFactory : public KParts::Factory +{ + Q_OBJECT + + public: + /** @brief Constructor */ + KXMLEditorFactory( QObject * pParent = 0, const char * pszName = 0 ); + /** @brief Destructor */ + virtual ~KXMLEditorFactory(); + + /** @short Creates part object, depending on given part class */ + virtual KParts::Part * createPartObject( QWidget * pParentWidget = 0, const char * pszWidgetName = 0, QObject * pParent = 0, const char * pszName = 0, const char * pszClassName = "KParts::Part", const QStringList & args = QStringList() ); + + static KInstance * instance(); + static KXEConfiguration * configuration(); + + private: + static KInstance * s_instance; + + /** @brief Our configuration - the same for all parts. */ + static KXEConfiguration * s_pKXEConfig; +}; + +#endif diff --git a/part/kxmleditorpart.cpp b/part/kxmleditorpart.cpp new file mode 100644 index 0000000..6abe508 --- /dev/null +++ b/part/kxmleditorpart.cpp @@ -0,0 +1,1923 @@ +/*************************************************************************** + kxmleditorpart.cpp - description + ------------------- + begin : Wed Sep 19 2001 + copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team + email : OleBowle@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "kxmleditorpart.h" +#include "kxmleditorfactory.h" + +#include "kxedocument.h" + +#include "kxeconfiguration.h" +#include "kxenewfilesettings.h" +#include "kxearchiveextssettings.h" +#include "kxeprintsettings.h" +#include "kxetextviewsettings.h" + +#include "commands_edit.h" +#include "commands_insert.h" + +#include "kxe_viewelement.h" +#include "kxe_treeviewitem.h" + +#include "kxesearchdialog.h" +#include "kxechoosestringdialog.h" +#include "kxeelementdialog.h" +#include "kxeattributedialog.h" +#include "kxeprocinstrdialog.h" +#include "kxespecprocinstrdialog.h" +#include "kxefilenewdialog.h" +#include "kxechardatadialog.h" +#include "kxeattachdialogbase.h" +#include "kxetexteditordialog.h" + +#include "actions.h" +#include "qdom_add.h" + +#include <kinstance.h> +#include <kdebug.h> +#include <klocale.h> +#include <kaction.h> +#include <kstdaction.h> +#include <kpopupmenu.h> +#include <kiconloader.h> +#include <kmessagebox.h> +#include <kprinter.h> +#include <ktar.h> +#include <kzip.h> +#include <ktempfile.h> +#include <kconfig.h> +#include <kurlrequester.h> +#include <kcommand.h> +#include <ktoolbar.h> +#include <kfiledialog.h> + +#include <qregexp.h> +#include <qtextcodec.h> +#include <qstringlist.h> +#include <qsplitter.h> +#include <qtabwidget.h> +#include <qtextedit.h> +#include <qcombobox.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qclipboard.h> +#include <qdragobject.h> +#include <qapplication.h> +#include <qbuffer.h> +#include <qlabel.h> +#include <qpainter.h> +#include <qpaintdevicemetrics.h> +#include <qevent.h> + +#include "dcopiface_part_ro.h" // DCOP Iface + +#define CONFIG_MAIN_SPLITTER_SIZES "Main splitter sizes" + + +KXMLEditorPart::KXMLEditorPart( bool fReadWrite, KXEDocument* pDocument, QWidget * pParent, const char * pszName ) + : KParts::ReadWritePart(pParent,pszName), + m_pDlgSearch(0), + m_pDocument(0) +{ + ////////////////////////////// + // INIT PART + ////////////////////////////// + + setInstance(KXMLEditorFactory::instance()); + + if(fReadWrite) + m_pBrowserExt = 0L; // Create Browser extension only for read-only part + else + m_pBrowserExt = new KXMLEditorBrowserExtension( this, "KXMLEditorPart browser extension" ); + + m_pPrinter = 0L; + + m_bAlreadyModified = false; + + ////////////////////////////// + // CREATE ACTIONS + ////////////////////////////// + + // file actions + if(fReadWrite) + { + KStdAction::save(this, SLOT(save()), actionCollection()); + KStdAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection()); + } + + // edit actions + m_pActEditFind = KStdAction::find( this, SLOT(slotEditFind()), actionCollection()); + m_pActEditFindNext = KStdAction::findNext( this, SLOT(slotEditFindNext()), actionCollection()); + m_pActEditDeselect = new KAction( i18n("D&eselect Node"), CTRL+Key_E, this, + SLOT(slotEditDeselect()), actionCollection(), "deselect" ); + + // view actions + m_pActViewNodeUp = new KAction( i18n("To &Parent Node"), "up", 0, this, + SLOT(slotViewNodeUp()), actionCollection(), "treeitem_up" ); + + m_pActViewExpNode = new KToolBarPopupAction( i18n("&Expand Node"), "expand_node", CTRL+Key_Plus, this, + SLOT(slotViewExpNode()), actionCollection(), "treeitem_expand" ); + KPopupMenu * pMenuExpNode = m_pActViewExpNode->popupMenu(); + connect( pMenuExpNode, SIGNAL(activated(int)), this, SLOT(slotViewExpNode(int)) ); + for ( uint i = 1; i <= 8; i++ ) + pMenuExpNode->insertItem( i18n("Expand To Level %1").arg(i), i-1 ); + + m_pActViewColNode = new KToolBarPopupAction( i18n("&Collapse Node"), "collapse_node", CTRL+Key_Minus, this, + SLOT(slotViewColNode()), actionCollection(), "treeitem_collapse" ); + KPopupMenu * pMenuColNode = m_pActViewColNode->popupMenu(); + connect( pMenuColNode, SIGNAL(activated(int)), this, SLOT(slotViewColNode(int)) ); + for ( uint i = 0; i <= 7; i++ ) + pMenuColNode->insertItem( i18n("Collapse To Level %1").arg(i), i ); + + // bookmark actions + m_pActBookmarksToggle = new KAction( i18n("&Toggle Bookmark"), "bookmark_add", CTRL+Key_B, this, + SLOT(slotBookmarksToggle()), actionCollection(), "bookmark_toggle" ); + m_pActBookmarksPrev = new KAction( i18n("&Previous Bookmark"), "bookmark_prev", SHIFT+Key_F5, this, + SLOT(slotBookmarksPrev()), actionCollection(), "bookmark_prev" ); + m_pActBookmarksNext = new KAction( i18n("&Next Bookmark"), "bookmark_next", Key_F5, this, + SLOT(slotBookmarksNext()), actionCollection(), "bookmark_next" ); + + // settings actions + new KAction( i18n("&Configure KXMLEditor..."), "configure", 0, this, + SLOT (slotConfigure()), actionCollection(), "configure" ); + + // path toolbar + m_pActPathCombo = new KXmlEditorComboAction( i18n("Path Bar"), 0, this, + SLOT(slotPathSelected(const QString &)), actionCollection(), "path_combo" ); + new KAction( i18n("Clear Path Bar"), BarIcon("locationbar_erase", 16), 0, this, + SLOT(slotPathClear()), actionCollection(), "path_clear" ); + QLabel *m_locationLabel = new ToolbarLabel( i18n("Path: ") ); + new KWidgetAction( m_locationLabel, i18n("Path: "), 0, this, 0, actionCollection(), "path_label" ); + m_locationLabel->setBuddy( m_pActPathCombo->comboBox()); + + if ( ! fReadWrite ) + { + setXMLFile( "kxmleditorpartBrowseUI.rc", true ); + + KStdAction::cut( m_pBrowserExt, SLOT(slotEditCut()), actionCollection(), "cut" ); + KStdAction::copy( m_pBrowserExt, SLOT(slotEditCopy()), actionCollection(), "copy" ); + KStdAction::paste( m_pBrowserExt, SLOT(slotEditPaste()), actionCollection(), "paste"); + + m_pCmdHistory = 0L; + + m_pActVersionEncoding = 0L; + m_pActAttachSchema = 0L; + m_pActDetachSchema = 0L; + m_pActAttachStylesheet = 0L; + m_pActDetachStylesheet = 0L; + } + else + { + // document specific actions here + m_pActVersionEncoding = new KAction( i18n("&Version && Encoding..."), 0, 0, this, SLOT(slotActVersionEncoding()), actionCollection(), "xml_ins_spec_procins" ); + m_pActAttachSchema = new KAction(i18n("Attach Schema..."),0,0,this,SLOT(slotActAttachSchema()), actionCollection(), "xml_attach_schema"); + m_pActDetachSchema = new KAction(i18n("Detach Schema"),0,0,this,SLOT(slotActDetachSchema()), actionCollection(), "xml_detach_schema"); + m_pActAttachStylesheet = new KAction(i18n("Attach Stylesheet..."),0,0,this,SLOT(slotActAttachStylesheet()), actionCollection(), "xml_attach_stylesheet"); + m_pActDetachStylesheet = new KAction(i18n("Detach Stylesheet"),0,0,this,SLOT(slotActDetachStylesheet()), actionCollection(), "xml_detach_stylesheet"); + + KStdAction::print( this, SLOT(slotActPrint()), actionCollection(), "print" ); + + m_pActAttachSchema->setEnabled(false); + m_pActDetachSchema->setEnabled(false); + m_pActDetachStylesheet->setEnabled(false); + + + // undo & redo + KStdAction::undo(this, SLOT(slotActUndo()), actionCollection()); + KStdAction::redo(this, SLOT(slotActRedo()), actionCollection()); + + m_pCmdHistory = new KCommandHistory(actionCollection()); + + m_pActEditCut = KStdAction::cut( this, SLOT(slotEditCut()), actionCollection()); + m_pActEditCopy = KStdAction::copy( this, SLOT(slotEditCopy()), actionCollection()); + m_pActEditPaste = KStdAction::paste( this, SLOT(slotEditPaste()), actionCollection()); + + // Move node Up & Down + m_pActXmlMoveNodeUp = new KAction( i18n("&Move Up"), "xml_move_item_up", CTRL+Key_U, this, SLOT(slotXmlMoveNodeUp()), actionCollection(), "xml_move_item_up" ); + m_pActXmlMoveNodeDown = new KAction( i18n("Move &Down"), "xml_move_item_down", CTRL+Key_D, this, SLOT(slotXmlMoveNodeDown()), actionCollection(), "xml_move_item_down" ); + + // Insert actions + m_pActXmlElementInsert = new KAction( i18n("&Element..."), "xml_insert_element", CTRL+SHIFT+Key_E, this, SLOT(slotXmlElementInsert()), actionCollection(), "xml_ins_element" ); + m_pActXmlAttributesAdd = new KAction( i18n("&Attribute..."), "xml_insert_attribute", CTRL+SHIFT+Key_A, this, SLOT(slotXmlAttributesAdd()), actionCollection(), "xml_add_attribute" ); + m_pActInsertText = new KAction( i18n("&Text..."), "xml_text", CTRL+SHIFT+Key_T, this, SLOT(slotActInsertText()), actionCollection(), "insert_text" ); + m_pActInsertCDATA = new KAction( i18n("C&DATA..."), "xml_cdata", CTRL+SHIFT+Key_D, this, SLOT(slotActInsertCDATA()), actionCollection(), "insert_cdata" ); + m_pActInsertComment = new KAction( i18n("&Comment..."), "xml_comment", CTRL+SHIFT+Key_C, this, SLOT(slotActInsertComment()), actionCollection(), "insert_comment" ); + m_pActXmlProcInstrInsert = new KAction( i18n("&Processing Instruction..."), "xml_insert_procins", CTRL+SHIFT+Key_P, this, SLOT(slotXmlProcInstrInsert()), actionCollection(), "xml_ins_procins" ); + + // Edit node properties + m_pActProperties = new KAction(i18n("&Properties..."),"edit",0,this,SLOT(slotActProperties()),actionCollection(),"edit_properties"); + m_pActEditRawXml = new KAction(i18n("Edit &raw XML..."), 0, 0, this, SLOT(slotActEditRawXml()),actionCollection(),"edit_as_raw_xml"); + + // delete actions + m_pActXmlAttributeDel = new KAction( i18n("&Delete"), "editdelete", 0, this, SLOT(slotXmlAttributeDel()), actionCollection(), "xml_del_attribute" ); + m_pActXmlAttributesDel = new KAction( i18n("Delete all Attributes..."), 0, 0, this, SLOT(slotXmlAttributesDel()), actionCollection(), "xml_del_attributes" ); + m_pActDelete = new KAction(i18n("&Delete"),"editdelete",0,this,SLOT(slotActDelete()),actionCollection(),"edit_delete"); + + setXMLFile( "kxmleditorpartEditUI.rc", true ); + + // we are not modified since we haven't done anything yet + setModified(false); + } + + ////////////////////////////// + // CREATE WIDGETS + ////////////////////////////// + + pSplitter = new QSplitter( pParent, "KXMLEditorPart main widget (Splitter)" ); + pSplitter->setFocusPolicy( QWidget::NoFocus ); + pSplitter->setOpaqueResize(true); + setWidget( pSplitter ); + + // create the tree view ------------------- + m_pViewTree = new KXE_TreeView( this, pSplitter, "KXMLEditorPart treeview" ); + + connect( m_pViewTree, SIGNAL(sigSelectionCleared(bool)), this, SLOT(slotSelectionCleared(bool)) ); + connect( m_pViewTree, SIGNAL(sigSelectionChanged(const QDomElement &)), this, SLOT(slotSelectionChanged(const QDomElement &)) ); + connect( m_pViewTree, SIGNAL(sigSelectionChanged(const QDomCharacterData &)), this, SLOT(slotSelectionChanged(const QDomCharacterData &)) ); + connect( m_pViewTree, SIGNAL(sigSelectionChanged(const QDomProcessingInstruction &)), this, SLOT(slotSelectionChanged(const QDomProcessingInstruction &)) ); + connect( m_pViewTree, SIGNAL(sigContextMenuRequested(const QString&,const QPoint&)), this, SLOT(slotContextMenuRequested(const QString&,const QPoint&)) ); + connect( m_pViewTree, SIGNAL(itemRenamed(QListViewItem *)), this, SLOT(slotItemRenamedInplace(QListViewItem *)) ); + connect( m_pViewTree, SIGNAL(sigKeyPressed(QKeyEvent* )),this,SLOT(slotTreeViewKeyPressed(QKeyEvent*))); + + // create tab widget ---------------------- + m_pTabWidget = new QTabWidget( pSplitter, "KXMLEditorPart tabwidget"); + m_pTabWidget->setFocusPolicy( QWidget::NoFocus ); + + // create element view + m_pViewElement = new KXE_ViewElement( m_pTabWidget, instance()->config(), "KXMLEditorPart element view" ); + m_pTabWidget->addTab( m_pViewElement, g_iconElement, i18n("Element") ); + connect( m_pViewElement, SIGNAL(sigContextMenuRequested(const QString&,const QPoint&)), this, SLOT(slotContextMenuRequested(const QString&,const QPoint&)) ); + connect( m_pViewElement, SIGNAL(sigAttributeNameChangedInplace(const QDomAttr&, const QString)), this, SLOT(slotAttributeNameChangedInplace(const QDomAttr&, const QString)) ); + connect( m_pViewElement, SIGNAL(sigAttributeValueChangedInplace(const QDomAttr&, const QString)), this, SLOT(slotAttributeValueChangedInplace(const QDomAttr&, const QString)) ); + + // create edit widget, that display XML character data contents + m_pViewContents = new QTextEdit( m_pTabWidget, "KXMLEditorPart contents view" ); + m_pTabWidget->addTab( m_pViewContents, g_iconText, i18n("Contents") ); + m_pViewContents->setReadOnly( true ); + m_pViewContents->setWordWrap( QTextEdit::NoWrap ); + m_pViewContents->setTextFormat(QTextEdit::PlainText); + + // create proc.instr. view + m_pViewProcInstr = new QTextEdit( m_pTabWidget, "KXMLEditorPart proc.instr. view" ); + m_pTabWidget->addTab( m_pViewProcInstr, g_iconProcessingInstruction, i18n("Proc.Instruction") ); + m_pViewProcInstr->setReadOnly( true ); + m_pViewProcInstr->setWordWrap( QTextEdit::NoWrap ); + + connect( this, SIGNAL(started(KIO::Job*)), this, SLOT(started()) ); + connect( this, SIGNAL(completed()), this, SLOT(completed()) ); + connect( this, SIGNAL(canceled(const QString &)), this, SLOT(canceled()) ); + + ////////////////////////////// + // INIT BEGIN STATE + ////////////////////////////// + + // Disable actions + if(m_pBrowserExt) + m_pBrowserExt->emit enableAction("copy", false); + else + m_pActEditCopy->setEnabled(false); + + m_pActEditFindNext->setEnabled(false); + m_pActEditDeselect->setEnabled(false); + m_pActViewNodeUp->setEnabled(false); + m_pActViewExpNode->setEnabled(false); + m_pActViewColNode->setEnabled(false); + m_pActBookmarksToggle->setEnabled(false); + m_pActBookmarksPrev->setEnabled(false); + m_pActBookmarksNext->setEnabled(false); + + if ( fReadWrite ) + { + m_pActEditCut->setEnabled(false); + m_pActEditPaste->setEnabled(true); + + m_pActXmlElementInsert->setEnabled(true); + m_pActXmlAttributesAdd->setEnabled(false); + m_pActXmlAttributesDel->setEnabled(false); + m_pActXmlProcInstrInsert->setEnabled(true); + m_pActInsertText->setEnabled(false); + m_pActInsertCDATA->setEnabled(false); + m_pActInsertComment->setEnabled(false); + m_pActXmlMoveNodeUp->setEnabled(false); + m_pActXmlMoveNodeDown->setEnabled(false); + m_pActDelete->setEnabled(false); + m_pActProperties->setEnabled(false); + m_pActEditRawXml->setEnabled(false); + } + + m_pTabWidget->setTabEnabled( m_pViewElement, false ); + m_pTabWidget->setTabEnabled( m_pViewContents, false ); + m_pTabWidget->setTabEnabled( m_pViewProcInstr, false ); + + setReadWrite(fReadWrite); + + // configuring splitter sizes + QValueList<int> list = instance()->config()->readIntListEntry(CONFIG_MAIN_SPLITTER_SIZES); + if (!list.isEmpty()) + pSplitter->setSizes(list); + + ////////////////////////////// + // INIT DCOP object (if any) + ////////////////////////////// + //m_pDCOPIface = NULL; + //m_pDCOPIface = new KXMLEditorPartIfaceReadOnly(this); + m_pDCOPIface = new KXMLEditorPartIfaceReadWrite(this); // temporarly to test openUrl + + setDocument(pDocument); + +} + +KXMLEditorPart::~KXMLEditorPart() +{ + // saving splitter configuration + KConfig *pConfig = instance()->config(); + pConfig->writeEntry( CONFIG_MAIN_SPLITTER_SIZES, pSplitter->sizes() ); + + if (m_pDCOPIface) + delete m_pDCOPIface; + + if (m_pDlgSearch) + delete m_pDlgSearch; + + if (m_pPrinter) + delete m_pPrinter; + + if (document()) + delete document(); + + delete m_pCmdHistory; +} + + +///////////////////////////////////////////////////////////////////// +// KPART FUNCTIONALITY +///////////////////////////////////////////////////////////////////// + +bool KXMLEditorPart::openFile() +{ + if( isModified() ) + kdError() << "KXMLEditorPart::openFile the current document is modified." << endl; + + document()->setURL(m_url); + bool bResult = document()->open(m_file); + updateActions(); + return bResult; +} + +bool KXMLEditorPart::saveFile() +{ + emit setStatusBarText( i18n("Saving file...") ); + + if( url().isEmpty() ) + { + return slotFileSaveAs(); + } + + // delegate this operation to underlying document object + document()->setURL(m_url); + bool bRetVal = document()->save(m_file); + + emit setStatusBarText( i18n("Ready.") ); + return bRetVal; +} + +void KXMLEditorPart::setModified( bool bModified ) +{ + KParts::ReadWritePart::setModified( bModified ); // base functionality + + if ( m_bAlreadyModified != bModified ) + { + m_bAlreadyModified = bModified; + + QString szNewCaption = m_url.prettyURL(); + emit setWindowCaption( szNewCaption ); + } + + // get a handle on our Save action and make sure it is valid + KAction *pActFileSave = actionCollection()->action(KStdAction::stdName(KStdAction::Save)); + if(!pActFileSave) + return; + + // if so, we either enable or disable it based on the current state + pActFileSave->setEnabled(bModified); + + // Update others actions + updateActions(); +} + +void KXMLEditorPart::setReadWrite( bool fReadWrite ) +{ + m_pViewTree->setReadWrite(fReadWrite); + m_pViewElement->setReadWrite(fReadWrite); + + KParts::ReadWritePart::setReadWrite( fReadWrite ); // base functionality +} + +void KXMLEditorPart::started() +{ + kdDebug() << "KXMLEditorPart::started" << endl; +} +void KXMLEditorPart::completed() +{ + kdDebug() << "KXMLEditorPart::completed" << endl; +} +void KXMLEditorPart::canceled() +{ + kdDebug() << "KXMLEditorPart::canceled" << endl; +} + + +///////////////////////////////////////////////////////////////////// +// ACTION SLOTS +///////////////////////////////////////////////////////////////////// + +void KXMLEditorPart::slotActPrint() +{ + // this slot is called whenever the File->Print menu is selected, + // the Print shortcut is pressed (usually CTRL+P) or the Print toolbar + // button is clicked + if (!m_pPrinter) + m_pPrinter = new KPrinter; + + if (m_pPrinter->setup(widget())) + print(m_pPrinter); +} + +void KXMLEditorPart::slotActProperties() +{ + QDomNode* pNode = m_pViewTree->getSelectedNode(); + if (pNode) + { + if (pNode->isElement()) + slotXmlElementEdit(); + else if (pNode->isCharacterData()) + slotXmlCharDataEdit(); + else if (pNode->isProcessingInstruction()) + slotXmlProcInstrEdit(); + else + kdError() << "Unknown node selected."; + } +} + +void KXMLEditorPart::slotActDelete() +{ + QDomNode* pNode = m_pViewTree->getSelectedNode(); + + if (!m_pViewElement->hasFocus()) + { + // delete nodes selected there + if (pNode) + { + KCommand *pCmd = new KXEDeleteNodeCommand(document(), *pNode); + m_pCmdHistory->addCommand(pCmd); + } + } + else + { + // we can have also delete attribute selected on a element view + QDomAttr domAttr = m_pViewElement->getSelectedAttribute(); + if (!domAttr.isNull()) + { + QDomElement domElement = pNode->toElement(); + QDomAttr domAttr = m_pViewElement->getSelectedAttribute(); + + KCommand *pCmd = new KXEDeleteAttrCommand(document(), domElement, domAttr); + m_pCmdHistory->addCommand(pCmd); + } + } +} + +void KXMLEditorPart::slotEditCut() +{ + kdDebug() << "KXMLEditor " << k_funcinfo << endl; + + if(! isReadWrite()) + { + kdError() << "KXMLEditorPart::slotEditCut called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + + if(pNode) + { // copy to clipboard + slotEditCopy(); + + // and cut it + KCommand *pCmd = new KXECutCommand(document(), *pNode); + m_pCmdHistory->addCommand(pCmd); + } +} + +void KXMLEditorPart::slotEditCopy() +{ + kdDebug() << "KXMLEditor " << k_funcinfo << endl; + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + + if(pNode) + { + QTextDrag *pDrag = copyNode(m_pViewTree->getSelectedNode()); + if(pDrag) + QApplication::clipboard()->setData(pDrag); + } + else + kdError() << "KXMLEditorPart::slotEditCopy no element selected." << endl; +} + +void KXMLEditorPart::slotEditPaste() +{ + kdDebug() << "KXMLEditor " << k_funcinfo << endl; + + if(!isReadWrite()) + { + kdError() << "KXMLEditorPart::slotEditPaste called in readonly mode." << endl; + return; + } + + if (document()->documentElement().isNull()) + { + pasteNode(0, QApplication::clipboard()->data()); + } + else + { + pasteNode(m_pViewTree->getSelectedNode(), QApplication::clipboard()->data()); + } +} + +void KXMLEditorPart::slotEditFind() +{ + emit setStatusBarText( i18n("Search in XML tree ...") ); + + if ( ! m_pDlgSearch ) + { + m_pDlgSearch = new KXESearchDialog( widget(), "search dialog", true ); + } + + if ( m_pDlgSearch->exec() == KXESearchDialog::Accepted ) + slotEditFindNext(); + + m_pActEditFindNext->setEnabled(true); + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotEditFindNext() +{ + emit setStatusBarText( i18n("Search in XML tree ...") ); + + if ( ! m_pDlgSearch ) + { + kdDebug() << "KXMLEditorPart::slotEditFindNext implementation error - no search dialog" << endl; + emit setStatusBarText( i18n("Ready.") ); + return; + } + + // get node to start with (either the next node of the item selected at the tree view or documents root node) + QDomNode node = ( (m_pViewTree->getSelectedNode()) && (! m_pViewTree->getSelectedNode()->isNull()) ) ? domTool_nextNode(* m_pViewTree->getSelectedNode()) : document()->documentElement(); + + // start testing til the last node + while( ! node.isNull() ) + { + if ( domTool_match( node, m_pDlgSearch ) ) + { + m_pViewTree->selectNode(node); + emit setStatusBarText( i18n("Ready.") ); + return; + } + + node = domTool_nextNode(node); + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotXmlElementInsert() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlElementInsert called in readonly mode." << endl; + return; + } + + emit setStatusBarText( i18n("Inserting XML element into document...") ); + + KXEElementDialog dlg( widget(), "XML element dialog" ); + + if ( document()->documentElement().isNull() ) // the document doesn't + { // have a root element yet + if ( dlg.exec( false, true, false ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXEElementCommand(document(), document(), dlg.nsURI(), dlg.prefix(), dlg.name()); + m_pCmdHistory->addCommand(pCmd); + } + } + else // the document seems to + { // have a root element + QDomNode * pParentNode = m_pViewTree->getSelectedNode(); + + if ( (pParentNode) && (pParentNode->isElement()) ) + { + QDomElement domParentElement = pParentNode->toElement(); + + if ( dlg.exec( false, false, false ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXEElementCommand(document(), domParentElement, dlg.nsURI(), dlg.prefix(), dlg.name(), dlg.atTop()); + m_pCmdHistory->addCommand(pCmd); + } + } + else + kdError() << "KXMLEditorPart::slotXmlElementInsert no element selected." << endl; + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotXmlElementEdit() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlElementEdit called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isElement()) ) + { + kdError() << "KXMLEditorPart::slotXmlElementEdit no node selected or selected node is no XML element." << endl; + return; + } + + emit setStatusBarText( i18n("Editing XML element...") ); + + QDomElement domElement = pNode->toElement(); + + KXEElementDialog dlg( widget(), "XML element dialog" ); + + dlg.setPrefix(domElement.prefix()); + dlg.setName(domElement.tagName()); + if(!domElement.namespaceURI().isNull()) + dlg.setNsURI(domElement.namespaceURI() ); + + if ( dlg.exec( true, false, domElement.namespaceURI().isNull() ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXEEditElementCommand(document(), domElement, dlg.prefix(), dlg.name()); + m_pCmdHistory->addCommand(pCmd); + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotActEditRawXml() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotActEditRawXml called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isElement()) ) + { + kdError() << "KXMLEditorPart::slotActEditRawXml no node selected or selected node is no XML element." << endl; + return; + } + + emit setStatusBarText( i18n("Editing raw XML...") ); + + QDomElement domElement = pNode->toElement(); + + QString strXML; + + QTextStream streamXML(&strXML, IO_WriteOnly); + int iIndent = KXMLEditorFactory::configuration()->textview()->indentSteps(); + pNode->save(streamXML, iIndent); + + KXETextEditorDialog dlg(0, "Text dialog"); + dlg.setEditorText(strXML); + if((dlg.exec() == QDialog::Accepted) && (strXML != dlg.editorText())) + { + QString strXML = "<root>" + dlg.editorText() + "</root>"; + + // create XML documemt from text + QString strErrorMsg; + int iErrorLine, iErrorColumn; + QDomDocument doc; + + if(!doc.setContent(strXML, true, &strErrorMsg, &iErrorLine, &iErrorColumn) ) + { + kdDebug() << "KXMLEditorPart::slotActEditRawXml: Failed parsing the file." << endl; + + KMessageBox::error(m_pViewTree, + i18n("%1 in line %2, column %3").arg(strErrorMsg).arg(iErrorLine).arg(iErrorColumn), + i18n("Parsing error !")); + + return; + } + + // check if root item already exists + if(!doc.firstChild().firstChild().isElement()) + { + KMessageBox::sorry(m_pViewTree, i18n("You are changed root element to another node type, while editing !")); + return; + } + + QDomElement domNewElement = doc.firstChild().firstChild().toElement(); + KCommand *pCmd = new KXEEditRawXmlCommand(document(), domElement, domNewElement); + m_pCmdHistory->addCommand(pCmd); + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotXmlAttributesAdd() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlAttributesAdd called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isElement()) ) + { + kdError() << "KXMLEditorPart::slotXmlAttributesAdd no node selected or selected node is no XML element." << endl; + return; + } + + emit setStatusBarText( i18n("Add attribute...") ); + + KXEAttributeDialog dlg( widget(), "attribute dialog" ); + + QDomElement domOwnerElement = pNode->toElement(); + if ( dlg.exec( ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXEAttributeCommand(document(), domOwnerElement, dlg.attributeNamespace(), dlg.QName(), dlg.Value()); + m_pCmdHistory->addCommand(pCmd); + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotXmlAttributesDel() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlAttributesDel called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isElement()) ) + { + kdError() << "KXMLEditorPart::slotXmlAttributesDel no node selected or selected node is no XML element." << endl; + return; + } + + if(KMessageBox::questionYesNo(0, i18n("Remove all attributes from selected node ?")) != KMessageBox::Yes) + return; + + emit setStatusBarText( i18n("Delete all attributes...") ); + + QDomElement domOwnerElement = pNode->toElement(); + + KCommand *pCmd = new KXEDeleteAllAttribCommand(document(), domOwnerElement); + m_pCmdHistory->addCommand(pCmd); + + emit setStatusBarText( i18n("Ready.") ); +} + + +void KXMLEditorPart::slotXmlAttributeDel() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlAttributeDel called in readonly mode." << endl; + + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isElement()) ) + { + kdError() << "KXMLEditorPart::slotXmlAttributeDel no node selected or selected node is no XML element." << endl; + return; + } + + emit setStatusBarText( i18n("Delete attribute...") ); + + QDomElement domElement = pNode->toElement(); + QDomAttr domAttr = m_pViewElement->getSelectedAttribute(); + + KCommand *pCmd = new KXEDeleteAttrCommand(document(), domElement, domAttr); + m_pCmdHistory->addCommand(pCmd); + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotXmlProcInstrInsert() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlProcInstrInsert called in readonly mode." << endl; + return; + } + + KXEProcInstrDialog dlg( widget(), "proc. instr. dialog" ); + + QDomNode * pParentNode = m_pViewTree->getSelectedNode(); + if ( (pParentNode) && (!pParentNode->isElement()) ) + { + kdError() << k_funcinfo << " The selected node is no XML element." << endl; + return; + } + else + { + if ( ! pParentNode ) // no node selected -> the new node should be a direct child of the document + { + if ( dlg.exec( false, true ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXEProcInstrCommand(document(), document(), dlg.atTop(), dlg.target(), dlg.data()); + m_pCmdHistory->addCommand(pCmd); + } + } + else + { + if ( dlg.exec( false, false ) == QDialog::Accepted ) + { + QDomElement domParentElement = pParentNode->toElement(); + + KCommand *pCmd = new KXEProcInstrCommand(document(), domParentElement, dlg.atTop(), dlg.target(), dlg.data()); + m_pCmdHistory->addCommand(pCmd); + } + } + } + + emit setStatusBarText( i18n("Inserting processing instruction into document...") ); + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotXmlProcInstrEdit() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlProcInstrEdit called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isProcessingInstruction()) ) + { + kdError() << "KXMLEditorPart::slotXmlProcInstrEdit no node selected or selected node is no processing instruction." << endl; + return; + } + + emit setStatusBarText( i18n("Editing processing instruction...") ); + + QDomProcessingInstruction domProcInstr = pNode->toProcessingInstruction(); + + // We have two different kinds of processing instructions: + // - a special one - defining the documents XML version and encoding + // - others + // and both cases require different dialogs. + if( domProcInstr.target() == "xml" ) // 1st case (special proc.instr.) + document()->actVersionEncoding(); + else // 2nd case (others) + { + KXEProcInstrDialog dlg( widget(), "proc. instr. dialog" ); + + dlg.setTarget(domProcInstr.target()); + dlg.setData(domProcInstr.data()); + + if ( dlg.exec( true, false ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXEEditProcInstrCommand(document(), domProcInstr, dlg.data()); + m_pCmdHistory->addCommand(pCmd); + } + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotActInsertText() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotActInsertText called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isElement()) ) + { + kdError() << "KXMLEditorPart::slotActInsertText no element selected." << endl; + return; + } + + emit setStatusBarText( i18n("Inserting text into document...") ); + + KXECharDataDialog dlg( widget()); + dlg.setCaption(i18n("Insert text")); + + QDomElement domParentElement = pNode->toElement(); + + if ( dlg.exec( false ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXECharDataCommand(document(), domParentElement, dlg.atTop(), CharDataTextNode, dlg.contents()); + m_pCmdHistory->addCommand(pCmd); + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotActInsertCDATA() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotActInsertCDATA called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isElement()) ) + { + kdError() << "KXMLEditorPart::slotActInsertCDATA no element selected." << endl; + return; + } + + emit setStatusBarText( i18n("Inserting CDATA into document...") ); + + KXECharDataDialog dlg( widget()); + dlg.setCaption(i18n("Insert CDATA")); + + QDomElement domParentElement = pNode->toElement(); + + if ( dlg.exec( false ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXECharDataCommand(document(), domParentElement, dlg.atTop(), CharDataCDATASection, dlg.contents()); + m_pCmdHistory->addCommand(pCmd); + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotActInsertComment() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotActInsertComment called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isElement()) ) + { + kdError() << "KXMLEditorPart::slotActInsertComment no element selected." << endl; + return; + } + + emit setStatusBarText( i18n("Inserting comment into document...") ); + + KXECharDataDialog dlg( widget()); + dlg.setCaption(i18n("Insert comment")); + + QDomElement domParentElement = pNode->toElement(); + + if ( dlg.exec( false ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXECharDataCommand(document(), domParentElement, dlg.atTop(), CharDataComment, dlg.contents()); + m_pCmdHistory->addCommand(pCmd); + } + emit setStatusBarText( i18n("Ready.") ); +} + + + +void KXMLEditorPart::slotXmlCharDataEdit() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlCharDataEdit called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( (!pNode) || (!pNode->isCharacterData()) ) + { + kdError() << "KXMLEditorPart::slotXmlCharDataEdit no node selected or selected node is no character data." << endl; + return; + } + + emit setStatusBarText( i18n("Editing character data...") ); + + QDomCharacterData domCharData = pNode->toCharacterData(); + + KXECharDataDialog dlg( widget() ); + + CharDataKind eCharDataKind; + if(domCharData.isText()) + eCharDataKind = CharDataTextNode; + else + { + if(domCharData.isCDATASection()) + eCharDataKind = CharDataCDATASection; + else + eCharDataKind = CharDataComment; + } + + // dlg.setCharDataKind(eCharDataKind); + dlg.setContents(domCharData.data()); + + if ( dlg.exec( true ) == QDialog::Accepted ) + { + KCommand *pCmd = new KXEEditCharDataCommand(document(), domCharData, dlg.contents()); + m_pCmdHistory->addCommand(pCmd); + } + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotXmlMoveNodeUp() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlMoveNodeUp called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( ! pNode ) + { + kdError() << "KXMLEditorPart::slotXmlMoveNodeUp no node selected." << endl; + return; + } + + emit setStatusBarText( i18n("Moving node up...") ); + + KCommand *pCmd = new KXEUpCommand(document(), * pNode); + m_pCmdHistory->addCommand(pCmd); + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotXmlMoveNodeDown() +{ + if ( ! isReadWrite() ) + { + kdError() << "KXMLEditorPart::slotXmlMoveNodeDown called in readonly mode." << endl; + return; + } + + QDomNode * pNode = m_pViewTree->getSelectedNode(); + if ( ! pNode ) + { + kdError() << "KXMLEditorPart::slotXmlMoveNodeDown no node selected." << endl; + return; + } + + emit setStatusBarText( i18n("Moving node down...") ); + + KCommand *pCmd = new KXEDownCommand(document(), * pNode); + m_pCmdHistory->addCommand(pCmd); + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotBookmarksToggle() +{ + m_pViewTree->bookmarksToggle(); + m_pActBookmarksPrev->setEnabled(m_pViewTree->containsBookmarkedItems()); + m_pActBookmarksNext->setEnabled(m_pViewTree->containsBookmarkedItems()); +} + +void KXMLEditorPart::slotConfigure() +{ + emit setStatusBarText( i18n("Configure KXML Editor ...") ); + + KXMLEditorFactory::configuration()->showDialog(); + + emit setStatusBarText( i18n("Ready.") ); +} + +void KXMLEditorPart::slotPathSelected( ) +{ + +} + +void KXMLEditorPart::slotPathSelected( const QString & strPath ) +{ + QDomNode node = domTool_matchingNode( document()->toDocument(), strPath ); + if(node.isNull()) + { // node don't exists, remove item from combo + m_pActPathCombo->removeItem(strPath); + m_pActPathCombo->slotClearEdit(); + return; + } + + if(!m_pViewTree->selectNode(node)) + { // node not found, remove item from combo + m_pActPathCombo->removeItem(strPath); + m_pActPathCombo->slotClearEdit(); + } +} + +void KXMLEditorPart::slotPathClear() +{ + slotEditDeselect(); + m_pActPathCombo->slotFocusEdit(); +} + +void KXMLEditorPart::slotItemRenamedInplace( QListViewItem * pItem ) +{ + KXE_TreeViewItem * pXMLItem = static_cast <KXE_TreeViewItem*> (pItem); + + if ( ! pXMLItem->xmlNode()->isElement() ) // check, if it really represents an XML element + { + kdFatal() << "KXMLEditorPart " << k_funcinfo << " the given item doesn't represent an XML element." << endl; + return; + } + + QDomElement domElement = pXMLItem->xmlNode()->toElement(); + + if ( domElement.nodeName() != pItem->text(0) ) // if really something was changed + { + // else the element is "namespaced" + int nPosColon = pItem->text(0).find(':'); + + if ( nPosColon == -1 ) // if no namespace prefix was entered, + { + // check name + QString strMessage = KXEElementDialog::checkName(pItem->text(0)); + if(strMessage.length() > 0) + { + // restore old name + m_pViewTree->updateNodeChanged(domElement); + KMessageBox::sorry(m_pViewTree, strMessage); + return; + } + + // clear the elements namespace prefix + // and set the entered text as its tag name + KCommand *pCmd = new KXEEditElementCommand(document(), domElement, QString::null, pItem->text(0)); + m_pCmdHistory->addCommand(pCmd); + } + else + { + // otherwise split up the entered text by the first colon and + QString strPrefix(pItem->text(0).left(nPosColon)); + QString strName(pItem->text(0).right( pItem->text(0).length() - nPosColon - 1 )); + + // check name + QString strMessage = KXEElementDialog::checkName(strName); + if(strMessage.length() > 0) + { + // restore old name + m_pViewTree->updateNodeChanged(domElement); + KMessageBox::sorry(m_pViewTree, strMessage); + return; + } + + KCommand *pCmd = new KXEEditElementCommand( + document(), + domElement, + strPrefix, + strName + ); + + m_pCmdHistory->addCommand(pCmd); + } + + + if ( m_pViewTree->selectedItem() == pItem ) // and if the item is still selected + { + m_pActPathCombo->insertItem( domTool_getIconForNodeType(pXMLItem->xmlNode()->nodeType(), false), + domTool_getPath(*pXMLItem->xmlNode()) ); // the path combo + } + } +} + +void KXMLEditorPart::slotAttributeNameChangedInplace( const QDomAttr & domAttr, const QString strNewName ) +{ + if ( *m_pViewTree->getSelectedNode() == domAttr.ownerElement() ) // if the corresponding element + { // is still selected + KCommand *pCmd = new KXEEditAttrNameCommand(document(), domAttr, strNewName); + m_pCmdHistory->addCommand(pCmd); + } +} + +void KXMLEditorPart::slotAttributeValueChangedInplace( const QDomAttr & domAttr, const QString strNewValue ) +{ + if ( *m_pViewTree->getSelectedNode() == domAttr.ownerElement() ) // if the corresponding element + { // is still selected + KCommand *pCmd = new KXEEditAttrValueCommand(document(), domAttr, strNewValue); + m_pCmdHistory->addCommand(pCmd); + } +} + +///////////////////////////////////////////////////////////////////// +// MISC FUNCTIONS +///////////////////////////////////////////////////////////////////// + +/** Copy XML node into clipboard */ +QTextDrag * KXMLEditorPart::copyNode(QDomNode * pNode) +{ + QTextDrag *pDrag = 0; + QString strXML; + + QTextStream streamXML(&strXML, IO_WriteOnly); + int iIndent = KXMLEditorFactory::configuration()->textview()->indentSteps(); + pNode->save(streamXML, iIndent); + pDrag = new QTextDrag(strXML, m_pViewTree); + + /*if(pNode->isElement()) + pDrag->setSubtype(KXE_TreeViewItem::m_strSubtypeXML); + + if(pNode->isProcessingInstruction()) + pDrag->setSubtype(KXE_TreeViewItem::m_strSubtypeXML_procins); + + if(pNode->isText()) + pDrag->setSubtype(KXE_TreeViewItem::m_strSubtypeXML_text); + + if(pNode->isCDATASection()) + pDrag->setSubtype(KXE_TreeViewItem::m_strSubtypeXML_cdata); + + if(pNode->isComment()) + pDrag->setSubtype(KXE_TreeViewItem::m_strSubtypeXML_comment); */ + + return pDrag; +} + +//----------------------------------------------------------------------------- +// +// Paste XML node from clipboard into document +// +// pTargetNode - target node +// data - data to pasted +// +//----------------------------------------------------------------------------- +bool KXMLEditorPart::pasteNode(QDomNode * pTargetNode, QMimeSource *data) +{ + QString strText; + + // Drop XML Processing Instruction + if(QTextDrag::decode(data, strText)) + { if(strText.find("<?xml ") == 0) + { + KMessageBox::sorry(0, i18n("This processing instruction cannot be pasted here !")); + return false; + } + + //--- + + QString strXML = "<root>" + strText + "</root>"; + + // Paste clipboard contents as XML element + QString strErrorMsg; + int iErrorLine, iErrorColumn; + QDomDocument doc; + + if(!doc.setContent(strXML, true, &strErrorMsg, &iErrorLine, &iErrorColumn) ) + { kdDebug() << "KXMLEditorPart::pasteNode: Failed parsing the file." << endl; + + KMessageBox::error(m_pViewTree, + i18n("%1 in line %2, column %3").arg(strErrorMsg).arg(iErrorLine).arg(iErrorColumn), + i18n("Parsing error !")); + + return false; + } + + // Import parsed document to main document + if(doc.hasChildNodes()) + { if(pTargetNode == 0) + { // check if root item already exists + if(!document()->documentElement().isNull() /*(this->documentElement().isElement())*/ && (doc.firstChild().firstChild().isElement()) ) + { KMessageBox::sorry(m_pViewTree, i18n("Root element already exists !")); + return false; + } + + if(doc.documentElement().firstChild().isElement() == false) + { + KMessageBox::sorry(m_pViewTree, i18n("Node pasted to document must be element !")); + return false; + } + + // Append it as root node + QDomElement newNode = doc.documentElement().firstChild().cloneNode(true).toElement(); + + KCommand *pCmd = new KXEPasteToDocumentCommand(document(), document(), newNode); + m_pCmdHistory->addCommand(pCmd); + } + else + { QDomNode sourceNode = doc.firstChild().firstChild().cloneNode(true); + + /* + L.V. + + TESTING CODE FOR [ 925668 ] Attribute values in a copied element can't be changed. + + if(sourceNode.isElement()) + { + QDomElement domSourceElement = sourceNode.toElement(); + + QDomNamedNodeMap list = domSourceElement.attributes(); + unsigned int iLength = list.length(); + + + for ( unsigned int iRow = 0; iRow < iLength; iRow++ ) + { + QDomAttr a = list.item(iRow).toAttr(); + + QDomElement domOwnerElement = a.ownerElement(); + if(domOwnerElement.isNull()) + KMessageBox::sorry(m_pViewTree, i18n("Cloned owner is null !")); + }*/ + //--- + + if(pTargetNode->isElement()) + { + QDomElement domTargetElement = pTargetNode->toElement(); + KCommand *pCmd = new KXEPasteToElementCommand(document(), domTargetElement, sourceNode); + m_pCmdHistory->addCommand(pCmd); + return true; + } + + if(pTargetNode->isProcessingInstruction() && sourceNode.isProcessingInstruction()) + { // Replace contents of selected node + QDomProcessingInstruction domTargetProcInstr = pTargetNode->toProcessingInstruction(); + QDomProcessingInstruction domSourceProcInstr = sourceNode.toProcessingInstruction(); + + KCommand *pCmd = new KXEPasteToProcInstrCommand(document(), domTargetProcInstr, domSourceProcInstr); + m_pCmdHistory->addCommand(pCmd); + return true; + } + + if(pTargetNode->isCharacterData() && sourceNode.isCharacterData()) + { // Replace contents of selected node + QDomCharacterData domTargetCharData = pTargetNode->toCharacterData(); + QDomCharacterData domSourceCharData = sourceNode.toCharacterData(); + + KCommand *pCmd = new KXEPasteToCharDataCommand(document(), domTargetCharData, domSourceCharData); + m_pCmdHistory->addCommand(pCmd); + return true; + } + + KMessageBox::sorry(m_pViewTree, i18n("Incompactible node types for drag&drop !")); + return false; + } + } + return true; + } + return false; +} + +//----------------------------------------------------------------------------- +// +// Drag & Drop MOVE operation +// +// domTrgetElement - target element +// domSourceNode - source node +// +//----------------------------------------------------------------------------- +bool KXMLEditorPart::dropMoveNode(QDomElement & domTargetElement, QDomNode & domSourceNode) +{ + KCommand *pCmd = new KXEDragDropMoveCommand(document(), domTargetElement, domSourceNode); + m_pCmdHistory->addCommand(pCmd); + return true; +} + +///////////////////////////////////////////////////////////////////// +// PRINTING +///////////////////////////////////////////////////////////////////// + +// these defines should rather stay fixed and not configurable by the user. +#define headerMargin 30; +#define footerMargin 50; +#define m_printLinespace 0.4 // percent of font size used to make line indent + +int headerHeight, footerHeight; // used in few functions, nevertheless temporary... + +void KXMLEditorPart::print(KPrinter* pPrinter) +{ + // setup the printer. with Qt, you always "print" to a + // QPainter.. whether the output medium is a pixmap, a screen, or paper + QPainter p; + QPainter *painter = &p; + QFont font( KXMLEditorFactory::configuration()->print()->fontFamily(), + KXMLEditorFactory::configuration()->print()->fontSize() ); + + QPaintDeviceMetrics metrics((QPrinter*)pPrinter); // determining + int width = metrics.width(); // width and + int height = metrics.height(); // height of the page + + footerHeight = font.pointSize()+footerMargin; + headerHeight = font.pointSize()+headerMargin; + + int pageNumber = 0; + + painter->begin(pPrinter); // start print job + painter->setFont(font); // set up fonts for printout + printHeader(painter,pageNumber,0,width); // draw header on a first page + while (printPage (painter,pageNumber, + headerHeight,width, + height-headerHeight-footerHeight)) // and start printing loop + { + printFooter(painter, pageNumber, height-footerHeight,width); // draw footer at the end of that page + pageNumber++; + pPrinter->newPage(); + printHeader(painter,pageNumber,0,width); // draw header on new page + } + printFooter(painter,pageNumber,height-footerHeight,width); // draw footer on last page + painter->end(); // finish print job +} + +void KXMLEditorPart::printHeader(QPainter* painter,int pageNumber, int ypos, int width) +{ + pageNumber = pageNumber; + if ( KXMLEditorFactory::configuration()->print()->hasHeader() ) + { + painter->drawText(0,ypos,m_url.prettyURL()); + painter->drawLine(0,ypos,width,ypos); + } +} + +bool KXMLEditorPart::printPage(QPainter* painter,int pageNumber, int top, int width, int height) +{ + width = width; + if (pageNumber==0) + { + // initialization of working variables is done when + // first page is about to be printed + m_printLineNumber = 0; + m_printLines = QStringList::split( "\n", document()->toString(KXMLEditorFactory::configuration()->print()->indentSteps()) ); + } + int lineHeight = (int)(painter->font().pointSize()*(1+m_printLinespace)); + int y = top; + while ( y <= height ) + { + painter->drawText(0,y,m_printLines[m_printLineNumber]); + if (m_printLineNumber++==m_printLines.size()) + return false; // no more pages to print + y += lineHeight; + } + return true; // there are still some pages to print +} + +void KXMLEditorPart::printFooter(QPainter* painter,int pageNumber, int ypos, int width) +{ + if ( KXMLEditorFactory::configuration()->print()->hasFooter() ) + { + int fh = painter->font().pointSize(); + painter->drawText(0,ypos,i18n("Page %1").arg(pageNumber+1)); + painter->drawLine(0,ypos-fh,width,ypos-fh); + } +} + + +///////////////////////////////////////////////////////////////////// +// OTHER SLOTS +///////////////////////////////////////////////////////////////////// + +void KXMLEditorPart::slotTreeViewKeyPressed(QKeyEvent *e) +{ + // few keypresses are recognized and proper actions + // are executed. + switch (e->key()) + { + case Qt::Key_Delete : slotActDelete(); break; + case Qt::Key_Return : + case Qt::Key_Enter : slotActProperties(); break; + } +} + +void KXMLEditorPart::slotSelectionCleared(bool bRootElementExists) +{ + // Enable/Disable actions + if(m_pBrowserExt) + m_pBrowserExt->emit enableAction( "copy", false ); + else + m_pActEditCopy->setEnabled(false); + + m_pActEditDeselect->setEnabled(false); + m_pActViewNodeUp->setEnabled(false); + m_pActViewExpNode->setEnabled(false); + m_pActViewColNode->setEnabled(false); + m_pActBookmarksToggle->setEnabled(false); + + if ( isReadWrite() ) + { + m_pActEditCut->setEnabled(false ); + m_pActEditPaste->setEnabled(true ); + + m_pActXmlElementInsert->setEnabled(!bRootElementExists); + m_pActXmlAttributesAdd->setEnabled(false); + m_pActXmlAttributesDel->setEnabled(false); + m_pActXmlProcInstrInsert->setEnabled(true); + m_pActInsertText->setEnabled(false); + m_pActInsertCDATA->setEnabled(false); + m_pActInsertComment->setEnabled(false); + m_pActXmlMoveNodeUp->setEnabled(false); + m_pActXmlMoveNodeDown->setEnabled(false); + m_pActDelete->setEnabled(false); + m_pActProperties->setEnabled(false); + m_pActEditRawXml->setEnabled(false); + } + + m_pActPathCombo->slotClearEdit(); + + // change views + m_pViewContents->clear(); + + m_pTabWidget->setTabEnabled( m_pViewElement, false ); + m_pTabWidget->setTabEnabled( m_pViewContents, false ); + m_pTabWidget->setTabEnabled( m_pViewProcInstr, false ); + + m_pTabWidget->showPage( m_pViewContents ); + + // change path combo + m_pActPathCombo->slotClearEdit(); +} + +void KXMLEditorPart::slotSelectionChanged( const QDomElement & selectedNode) +{ + // Enable/Disable actions + if(m_pBrowserExt) + m_pBrowserExt->emit enableAction( "copy", true ); + else + m_pActEditCopy->setEnabled(true); + + m_pActEditDeselect->setEnabled(true); + m_pActViewNodeUp->setEnabled( ! selectedNode.parentNode().isNull() ); // disable if it's a root item + m_pActViewExpNode->setEnabled( ! selectedNode.firstChild().isNull() ); // no childs -> disable + m_pActViewColNode->setEnabled( ! selectedNode.firstChild().isNull() ); // no childs -> disable + m_pActBookmarksToggle->setEnabled(true); + + if ( isReadWrite() ) + { + m_pActEditCut->setEnabled(true); + m_pActEditPaste->setEnabled(true); + + m_pActXmlElementInsert->setEnabled(true); + m_pActXmlAttributesAdd->setEnabled(true); + m_pActXmlAttributesDel->setEnabled( (selectedNode.attributes().count() != 0) ); + m_pActXmlProcInstrInsert->setEnabled(true); +// m_pActXmlCharDataInsert->setEnabled(true); + m_pActInsertText->setEnabled(true); + m_pActInsertCDATA->setEnabled(true); + m_pActInsertComment->setEnabled(true); + m_pActDelete->setEnabled(true); + m_pActProperties->setEnabled(true); + m_pActEditRawXml->setEnabled(true); + + if ( selectedNode.parentNode().isDocument() ) + { + m_pActXmlMoveNodeUp->setEnabled(false); + m_pActXmlMoveNodeDown->setEnabled(false); + } + else + { + m_pActXmlMoveNodeUp->setEnabled( ! selectedNode.previousSibling().isNull() ); + m_pActXmlMoveNodeDown->setEnabled( ! selectedNode.nextSibling().isNull() ); + } + } + + // change views + m_pViewElement->slotChange(selectedNode); + + m_pTabWidget->setTabEnabled( m_pViewElement, true ); + m_pTabWidget->setTabEnabled( m_pViewContents, false ); + m_pTabWidget->setTabEnabled( m_pViewProcInstr, false ); + + m_pTabWidget->showPage(m_pViewElement); + + // change path combo + m_pActPathCombo->insertItem( domTool_getIconForNodeType(selectedNode.nodeType(), false), domTool_getPath(selectedNode) ); +} + +void KXMLEditorPart::slotSelectionChanged( const QDomCharacterData & selectedNode ) +{ + // Enable/Disable actions + if(m_pBrowserExt) + m_pBrowserExt->emit enableAction( "copy", true ); + else + m_pActEditCopy->setEnabled(true); + + m_pActEditDeselect->setEnabled(true); + m_pActViewNodeUp->setEnabled( ! selectedNode.parentNode().isNull() ); // disable if it's a root item + m_pActViewExpNode->setEnabled(false); + m_pActViewColNode->setEnabled(false); + m_pActBookmarksToggle->setEnabled(true); + + if ( isReadWrite() ) + { + m_pActEditCut->setEnabled(true); + m_pActEditPaste->setEnabled(true); + + m_pActXmlElementInsert->setEnabled(false); + m_pActXmlAttributesAdd->setEnabled(false); + m_pActXmlAttributesDel->setEnabled(false); + m_pActXmlProcInstrInsert->setEnabled(false); + m_pActInsertText->setEnabled(false); + m_pActInsertCDATA->setEnabled(false); + m_pActInsertComment->setEnabled(false); + m_pActXmlMoveNodeUp->setEnabled( ! selectedNode.previousSibling().isNull() ); + m_pActXmlMoveNodeDown->setEnabled( ! selectedNode.nextSibling().isNull() ); + m_pActDelete->setEnabled(true); + m_pActProperties->setEnabled(true); + m_pActEditRawXml->setEnabled(false); + } + + // change views + m_pViewContents->setText( selectedNode.data() ); + + m_pTabWidget->setTabEnabled( m_pViewElement, false ); + m_pTabWidget->setTabEnabled( m_pViewContents, true ); + m_pTabWidget->setTabEnabled( m_pViewProcInstr, false ); + + m_pTabWidget->showPage( m_pViewContents ); + + // change path combo + m_pActPathCombo->insertItem( domTool_getIconForNodeType(selectedNode.nodeType(), false), domTool_getPath(selectedNode) ); +} + +void KXMLEditorPart::slotSelectionChanged( const QDomProcessingInstruction & selectedNode ) +{ + // Enable/Disable actions + if(m_pBrowserExt) + m_pBrowserExt->emit enableAction( "copy", true ); + else + m_pActEditCopy->setEnabled(true); + + m_pActEditDeselect->setEnabled(true); + m_pActViewNodeUp->setEnabled( ! selectedNode.parentNode().isNull() ); // disable if it's a root item + m_pActViewExpNode->setEnabled(false); + m_pActViewColNode->setEnabled(false); + m_pActBookmarksToggle->setEnabled(true); + + if ( isReadWrite() ) + { + m_pActEditCut->setEnabled(true); + m_pActEditPaste->setEnabled(true); + + m_pActXmlAttributesAdd->setEnabled(false); + m_pActXmlAttributesDel->setEnabled(false); + m_pActXmlProcInstrInsert->setEnabled(false); + m_pActInsertText->setEnabled(false); + m_pActInsertCDATA->setEnabled(false); + m_pActInsertComment->setEnabled(false); + m_pActDelete->setEnabled(true); + m_pActProperties->setEnabled(true); + m_pActEditRawXml->setEnabled(false); + m_pActXmlElementInsert->setEnabled(selectedNode.parentNode().isDocument() && + document()->documentElement().isNull()); + + if ( selectedNode.parentNode().isDocument() ) + { + m_pActXmlMoveNodeUp->setEnabled(false); + m_pActXmlMoveNodeDown->setEnabled(false); + } + else + { + m_pActXmlMoveNodeUp->setEnabled( ! selectedNode.previousSibling().isNull() ); + m_pActXmlMoveNodeDown->setEnabled( ! selectedNode.nextSibling().isNull() ); + } + } + + // change views + m_pViewProcInstr->setText( selectedNode.data() ); + + m_pTabWidget->setTabEnabled( m_pViewElement, false ); + m_pTabWidget->setTabEnabled( m_pViewContents, false ); + m_pTabWidget->setTabEnabled( m_pViewProcInstr, true ); + + m_pTabWidget->showPage( m_pViewProcInstr ); + + // change path combo + m_pActPathCombo->insertItem( domTool_getIconForNodeType(selectedNode.nodeType(), false), domTool_getPath(selectedNode) ); +} + +void KXMLEditorPart::slotContextMenuRequested( const QString & szMenuName, const QPoint & pos ) +{ + QWidget * pContainer = hostContainer(szMenuName); + + if ( ! pContainer ) + { + kdError() << "KXMLEditor " << k_funcinfo << " Couldn't get a container widget for the given menu name (" << szMenuName << ")" << endl; + return; + } + + if ( ! pContainer->inherits("KPopupMenu") ) + { + kdError() << "KXMLEditor " << k_funcinfo << " Wrong container widget" << endl; + return; + } + + KPopupMenu * pMenu = static_cast <KPopupMenu*> (pContainer); + pMenu->popup( pos ); +} + + +///////////////////////////////////////////////////////////////////// +// FUNCTIONS CALLED FROM KXECommand CHILD CLASSES +///////////////////////////////////////////////////////////////////// + +void KXMLEditorPart::updateNodeCreated(const QDomNode & node) +{ + m_pViewTree->updateNodeCreated(node); +} + +void KXMLEditorPart::updateNodeDeleted( const QDomNode & node ) +{ + m_pViewTree->updateNodeDeleted(node); + + // if root element deleted, enable Insert Element + if(node.isElement() && (m_pViewTree->firstChild() == 0) && (isReadWrite())) + m_pActXmlElementInsert->setEnabled(true); +} + +void KXMLEditorPart::updateNodeChanged( const QDomElement & domElement ) +{ + m_pViewTree->updateNodeChanged(domElement); + m_pViewElement->slotChange(domElement); +} + +void KXMLEditorPart::updateNodeChanged( const QDomCharacterData & domCharData ) +{ + m_pViewTree->updateNodeChanged(domCharData); + m_pViewContents->setText( domCharData.data() ); +} + +void KXMLEditorPart::updateNodeChanged( const QDomProcessingInstruction &domProcInstr ) +{ + m_pViewTree->updateNodeChanged(domProcInstr); + m_pViewProcInstr->setText( domProcInstr.data() ); +} + +void KXMLEditorPart::updateNodeMoved( const QDomNode & domNode ) +{ + m_pViewTree->updateNodeMoved(domNode); +} + + +bool KXMLEditorPart::slotFileSaveAs() +{ + emit setStatusBarText( i18n("Saving file with a new filename...") ); + + KFileDialog dlg( QDir::currentDirPath(), // start dir. + i18n(FILE_DIALOG_FILTER), // filter + widget(), // parent + "file dialog for saving", // name + true ); // modal + dlg.setCaption( i18n("Save as...") ); + dlg.setOperationMode( KFileDialog::Saving ); + dlg.exec(); + + KURL url = dlg.selectedURL(); + bool bRetVal = false; + + if(!url.isEmpty()) + { + // append filetype if necessary + if(dlg.currentFilter() != "*.*") + { QString strExtension = dlg.currentFilter(); + strExtension.remove('*'); + + if(strExtension != url.fileName().right(strExtension.length())) + url.setFileName(url.fileName() + strExtension ); + } + + if((bRetVal = saveAs(url))) // something may go wrong + { + emit sigAddRecentURL(url); + setModified(false); + } + } + + emit setStatusBarText( i18n("Ready.") ); + return bRetVal; +} + +void KXMLEditorPart::slotDocOpened() +{ +// I temporary introduced code to measure the loading time using +// the different tree view item initialization modes. +// Simply open a document, remember the measured time difference, +// change the mode (in the configuration dialog), load the +// same document again and compare the measurements. +// Olaf +// +// TODO: the three lines operating with the QTime objects +// can be removed later + + // update the view + m_pViewTree->updateClear(); + int i = document()->childNodes().length(); + //QTime t1 = QTime::currentTime(); //TODO: remove this line later (Olaf) + while ( i > 0 ) + { + i--; + m_pViewTree->updateNodeCreated( document()->childNodes().item(i) ); + } + + //QTime t2 = QTime::currentTime(); //TODO: remove this and the next line later (Olaf) + //kdDebug() << "KXMLEditorPart::slotDocOpened() time difference: " << t1.msecsTo(t2) << " msecs" << endl; + + m_pActPathCombo->slotClear(); +} + +void KXMLEditorPart::setDocument(KXEDocument *pDocument) +{ + // detach previously used document + if (m_pDocument) + { + disconnect (m_pDocument,0,this,0); + } + m_pDocument = pDocument; + if (pDocument) + { + // open document notification + connect(pDocument,SIGNAL(sigOpened()),this,SLOT(slotDocOpened())); + // document modification is also dispatched + connect(pDocument,SIGNAL(sigModified(bool)),this,SLOT(setModified(bool))); + // update notifications + connect(pDocument,SIGNAL(sigNodeChanged(const QDomElement&)),this,SLOT(updateNodeChanged(const QDomElement&))); + connect(pDocument,SIGNAL(sigNodeChanged(const QDomProcessingInstruction&)),this,SLOT(updateNodeChanged(const QDomProcessingInstruction&))); + connect(pDocument,SIGNAL(sigNodeChanged(const QDomCharacterData&)),this,SLOT(updateNodeChanged(const QDomCharacterData&))); + connect(pDocument,SIGNAL(sigNodeCreated(const QDomNode&)),this,SLOT(updateNodeCreated(const QDomNode&))); + connect(pDocument,SIGNAL(sigNodeDeleted(const QDomNode&)),this,SLOT(updateNodeDeleted(const QDomNode&))); + connect(pDocument,SIGNAL(sigNodeMoved(const QDomNode&)),this,SLOT(updateNodeMoved(const QDomNode&))); + // merging document action collection + insertChildClient(pDocument); + } +} + +void KXMLEditorPart::slotActRedo() +{ + m_pCmdHistory->redo(); +} + +void KXMLEditorPart::slotActUndo() +{ + m_pCmdHistory->undo(); +} + +void KXMLEditorPart::slotActDetachStylesheet() +{ + KCommand *pCmd = m_pDocument->actDetachStylesheet(); + if(pCmd) m_pCmdHistory->addCommand(pCmd); +} + +void KXMLEditorPart::slotActAttachStylesheet() +{ + KCommand *pCmd = m_pDocument->actAttachStylesheet(); + if(pCmd) m_pCmdHistory->addCommand(pCmd); +} + +void KXMLEditorPart::slotActDetachSchema() +{ + KCommand *pCmd = m_pDocument->actDetachSchema(); + if(pCmd) m_pCmdHistory->addCommand(pCmd); +} + +void KXMLEditorPart::slotActAttachSchema() +{ + KCommand *pCmd = m_pDocument->actAttachSchema(); + if(pCmd) m_pCmdHistory->addCommand(pCmd); +} + +// Instert or edit special processing instruction <?xml ... ?> +void KXMLEditorPart::slotActVersionEncoding() +{ + KCommand *pCmd = m_pDocument->actVersionEncoding(); + if(pCmd) m_pCmdHistory->addCommand(pCmd); +} + +void KXMLEditorPart::updateActions() +{ + if(!m_pDocument) return; + if(!m_pActAttachSchema) return; // not in read-write mode + + // Schema + bool bSchemaExists = !m_pDocument->documentElement().isNull() && + // that's a question why it works with negated condition ?????? + !m_pDocument->documentElement().hasAttributeNS(SCHEMA_NAMESPACE,SCHEMA_ATTRIBUTE); + + m_pActAttachSchema->setEnabled(!m_pDocument->documentElement().isNull() && !bSchemaExists); + m_pActDetachSchema->setEnabled(bSchemaExists); + + // Stylesheet + m_pActDetachStylesheet->setEnabled(!m_pDocument->getSpecProcInstr("xml-stylesheet").isNull()); +} diff --git a/part/kxmleditorpart.desktop b/part/kxmleditorpart.desktop new file mode 100644 index 0000000..8aa3b97 --- /dev/null +++ b/part/kxmleditorpart.desktop @@ -0,0 +1,11 @@ +# KDE Config File +[Desktop Entry] +Name=KXMLEditorPart +Name[de]=KXMLEditor-Objekt +MimeType=text/xml; +ServiceTypes=KParts/ReadOnlyPart,KParts/ReadWritePart +X-KDE-Library=libkxmleditorpart +Type=Service +Icon=kxmleditor.png +MiniIcon=kxmleditor.png +# DocPath=kxmleditor/index.html diff --git a/part/kxmleditorpart.h b/part/kxmleditorpart.h new file mode 100644 index 0000000..319c577 --- /dev/null +++ b/part/kxmleditorpart.h @@ -0,0 +1,450 @@ +/*************************************************************************** + kxmleditorpart.h - description + ------------------- + begin : Wed Sep 19 2001 + copyright : (C) 2001, 2002, 2003 by The KXMLEditor Team + email : OleBowle@gmx.de + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KXMLEDITORPART_H +#define KXMLEDITORPART_H + +#include <kparts/part.h> +#include <kparts/browserextension.h> + +#include <qdom.h> +#include <qptrlist.h> + +#include "kxe_treeview.h" + +#define FILE_DIALOG_FILTER "*.xml|XML files\n*.xsl|XSL files\n*.xslt|XSLT files\n*.svg|SVG files\n*.xul|XUL files\n*.rc|Resource UI files\n*.ui|User Interface UI files\n*|All files" + +class QTabWidget; +class KXE_ViewElement; +class KXESearchDialog; +class QTextEdit; +class KAction; +class KToolBarPopupAction; +class KXmlEditorComboAction; +class QDomNode; +class QKeyEvent; +class KXMLEditorPartIfaceReadOnly; // DCOP interface +class KCommandHistory; +class KPrinter; +class QSplitter; +class KXEDocument; + + +/** @short This is the KPart of KXMLEditor. */ +class KXMLEditorPart : public KParts::ReadWritePart +{ + Q_OBJECT + +public: + /** @short Constructor + + Creates the actions, the view (widgets) and changes to "begin state". + */ + KXMLEditorPart( bool fReadWrite, KXEDocument* pDocument, QWidget * pParent, const char * pszName ); + + /** @short Destructor */ + virtual ~KXMLEditorPart(); + + /** @short Changes the behaviour of this part to readonly or readwrite. */ + virtual void setReadWrite( bool fReadWrite = true ); + + /** @short Returns the selected XML object's path or an empty string, if no object is selected. */ + QString getSelectedPath() const { return m_pViewTree->getSelectedPath(); } + + /** @short Copy XML node into clipboard */ + QTextDrag * copyNode(QDomNode *); + + /** @short Paste XML node from clipboard into document */ + bool pasteNode(QDomNode *, QMimeSource *); + + /** @short Drag&Drop move */ + bool dropMoveNode(QDomElement &, QDomNode &); + + /** @short Prints the document on specified printer. + @param pPrinter printer which will be used for printing. */ + virtual void print(KPrinter* pPrinter); + + /** @short Returns underlying document. */ + KXEDocument* document() { return m_pDocument; } + + /** @short Changes underlying document object */ + void setDocument(KXEDocument *pDocument); + +public slots: + /** + * Reimplemented from @ref KParts::KReadWritePart::setModified. + * + * Alters the window caption according to the given flag and + * calls the base functionality. + */ + virtual void setModified( bool fModified ); + + /** @short Updates tree view after creating new element */ + void updateNodeCreated(const QDomNode & node); + + /** @short Updates tree view after deleting new element */ + void updateNodeDeleted(const QDomNode & node); + + /** @short Updates tree view after change element properties */ + void updateNodeChanged( const QDomElement & domElement ); + + /** @short Updates tree view after change char. data properties */ + void updateNodeChanged( const QDomCharacterData & node ) ; + + /** @short Updates tree view after change proc. instr. properties */ + void updateNodeChanged( const QDomProcessingInstruction &domProcInstr ); + + /** @short Updates tree view after move node */ + void updateNodeMoved( const QDomNode & node ); + + /** + * @short Reimplemented from @ref KParts::KReadWritePart::setModified. + */ + virtual void setModified() { setModified(true); } + + /** @short Slot connected to File->Save As action. */ + bool slotFileSaveAs(); + + /** @short Inserts special proc.instruction into document. */ + void slotActVersionEncoding(); + + /** @short Called on user's action response. + Creates <?xml-stylesheet ...?> processing instruction + with reference to specified stylesheet URI. + */ + void slotActAttachStylesheet(); + + /** @short Called on user's action response. */ + void slotActDetachStylesheet(); + + /** @short Called on user's action response */ + void slotActDetachSchema(); + + /** @short Called on user's action response */ + void slotActAttachSchema(); + + /** @short Cut the marked text/object into the clipboard */ + void slotEditCut(); + + /** @short Copy the marked text/object into the clipboard */ + void slotEditCopy(); + + /** @short Paste the clipboard into the document */ + void slotEditPaste(); + + /** @short Displays search dialog and finds string in this tree view */ + void slotEditFind(); + + /** @short Finds next occurence of string in this tree view */ + void slotEditFindNext(); + + /** @short Deselects currently selected item */ + void slotEditDeselect() { m_pViewTree->editDeselect(); } + + /** @short Selects the selected item's parent item. */ + void slotViewNodeUp() { m_pViewTree->viewNodeUp(); } + + /** @short Expands the selected tree item's subtree. */ + void slotViewExpNode() { m_pViewTree->viewExpNode(-1); } + + /** @short Expands the selected tree item's subtree to the given level. */ + void slotViewExpNode( int nLevel ) { m_pViewTree->viewExpNode(nLevel); } + + /** @short Collapses the selected tree item's subtree. */ + void slotViewColNode() { m_pViewTree->viewColNode(0); } + + /** @short Collapses the selected tree item's subtree to the given level. */ + void slotViewColNode( int nLevel ) { m_pViewTree->viewColNode(nLevel); } + + /** @short Insert XML element into document */ + void slotXmlElementInsert(); + + /** @short Edit XML element */ + void slotXmlElementEdit(); + + /** @short Add attribute to an XML element. */ + void slotXmlAttributesAdd(); + + /** @short Delete all attributes of an XML element. */ + void slotXmlAttributesDel(); + + /** @short Delete an attribute of an XML element. */ + void slotXmlAttributeDel(); + + /** @short Insert proc.instruction into document */ + void slotXmlProcInstrInsert(); + + /** @short Edit proc.instruction */ + void slotXmlProcInstrEdit(); + + /* @short Insert text into element. */ + void slotActInsertText(); + + /* @short Insert CDATA section. */ + void slotActInsertCDATA(); + + /* @short Insert comment to element. */ + void slotActInsertComment(); + + /* @short Edit character data */ + void slotXmlCharDataEdit(); + + /* @short Moves a node up (change its position with its prev. siblings position) */ + void slotXmlMoveNodeUp(); + + /* @short Moves a node down (change its position with its next siblings position) */ + void slotXmlMoveNodeDown(); + + /** @short toggles bookmark on the selected item */ + void slotBookmarksToggle(); + + /** @short Searches for the previous bookmarked item */ + void slotBookmarksPrev() { m_pViewTree->bookmarksPrev(); } + + /** @short Searches for the next bookmarked item */ + void slotBookmarksNext() { m_pViewTree->bookmarksNext(); } + + /** @short Shows configuration dialog (@ref OptionsDialog) */ + void slotConfigure(); + + void slotPathSelected( const QString & szPath ); + void slotPathSelected(); + void slotPathClear(); + + /** @short Called when a tree view items text was changed via inplace-renaming. */ + void slotItemRenamedInplace( QListViewItem * pItem ); + + /** @short Called whan an attributes name was changed via inplace editing. */ + void slotAttributeNameChangedInplace( const QDomAttr &, const QString ); + + /** @short Called whan an attributes value was changed via inplace editing. */ + void slotAttributeValueChangedInplace( const QDomAttr &, const QString ); + + /** @short Called when File->Print or icon from the toolbar is selected. */ + void slotActPrint(); + + /** @short Slot for editing node properties. */ + void slotActProperties(); + + /** @short Slot for editing xml as a text in separate dialog window. */ + void slotActEditRawXml(); + + /** @short Slot for removing XML nodes. */ + void slotActDelete(); + + void slotTreeViewKeyPressed(QKeyEvent *e); + + /** @short Slot that performs redo function. */ + void slotActRedo(); + + /** @short Slot that performs undo function. */ + void slotActUndo(); + +protected: + + void updateActions(); + + /** @short Opens the file @ref KParts::ReadOnlyPart::m_file. */ + virtual bool openFile(); + + /** @short Saves the file @ref KParts::ReadOnlyPart::m_file. */ + virtual bool saveFile(); + + /** @short Draws header for printouts (made of file name). + @param painter a painter to use for drawing + @param pageNumber number of currently drawn page counted from 0 + @param ypos y coordinate of upper border of the header + @sa printPage() @sa printFooter() + */ + void printHeader(QPainter* painter, int pageNumber, int ypos, int width); + + /** @short Draws footer for printouts (page number). + @param painter a painter to use for drawing + @param pageNumber number of currently drawn page counted from 0 + @param ypos y coordinate of upper border of the footer + @sa printHeader() @sa printFooter() + */ + void printFooter(QPainter* painter,int pageNumber, int ypos, int width); + + /** @short Draws page for printing purposes. + + If there are more pages to print, method + returns true. Otherwise returns false. + @param painter a painter to use for srawing + @param pageNumber number of currently drawn page counted from 0 + @param top y coordinate of upper edge from where page should be drawn + @param width,height size of the medium (e.g. paper) + @sa printPage() @sa printHeader() + */ + bool printPage(QPainter* painter,int pageNumber, int top, int width, int height); + + /** @short Used in printing function printPage(). */ + unsigned int m_printLineNumber; + + /** @short Used in printing function printPage(). */ + QStringList m_printLines; + + // the actions + KAction * m_pActEditFind; + KAction * m_pActEditFindNext; + KAction * m_pActEditDeselect; + KAction * m_pActViewNodeUp; + KToolBarPopupAction * m_pActViewExpNode; + KToolBarPopupAction * m_pActViewColNode; + KAction * m_pActXmlElementInsert; + KAction * m_pActXmlAttributesAdd; + KAction * m_pActXmlAttributesDel; + KAction * m_pActXmlAttributeDel; + KAction * m_pActXmlProcInstrInsert; + KAction * m_pActInsertText; + KAction * m_pActInsertCDATA; + KAction * m_pActInsertComment; + KAction * m_pActXmlMoveNodeUp; + KAction * m_pActXmlMoveNodeDown; + KAction * m_pActBookmarksToggle; + KAction * m_pActBookmarksPrev; + KAction * m_pActBookmarksNext; + KXmlEditorComboAction * m_pActPathCombo; + + protected slots: + void started(); + void completed(); + void canceled(); + + /** @short Enables/disables actions and changes views */ + void slotSelectionCleared(bool); + + /** @short Enables/disables actions depending on the given XML element and changes views */ + void slotSelectionChanged( const QDomElement & ); + + /** @short Enables/disables actions and changes views */ + void slotSelectionChanged( const QDomCharacterData & ); + + /** @short Enables/disables actions and changes views */ + void slotSelectionChanged( const QDomProcessingInstruction & ); + + /** @short Shows the requested context menu at the given position. */ + void slotContextMenuRequested( const QString & szMenuName, const QPoint & pos ); + + /** @short Invoked everytime document has new content */ + void slotDocOpened(); + + private: + /** this view displays the XML-document's tree structure */ + KXE_TreeView * m_pViewTree; + + /** the tab widget, contains: m_pViewElement, m_pViewContents */ + QTabWidget * m_pTabWidget; + + /** widget to display XML element */ + KXE_ViewElement * m_pViewElement; + + /** edit widget for contents */ + QTextEdit * m_pViewContents; + + /** widget to display a proc.instr. */ + QTextEdit * m_pViewProcInstr; + + /** the search dialog, used for find action */ + KXESearchDialog * m_pDlgSearch; + + /** DCOP object having access to XML document. It may by NULL if no DCOP inteface is provided + or read only privided by @ref KXMLEditorPartReadOnlyIface or full read-write @ref KXMLEditorPartIface .*/ + KXMLEditorPartIfaceReadOnly * m_pDCOPIface; + + bool m_bAlreadyModified; + + /** our browser extension */ + KParts::BrowserExtension * m_pBrowserExt; + + /** @short Stores pointer to command history list, which provide undo/redo functionality */ + KCommandHistory* m_pCmdHistory; + + /** @short Action for cutting nodes to clipboard.*/ + KAction* m_pActEditCut; + + /** @short Action for copying nodes to clipboard.*/ + KAction* m_pActEditCopy; + + /** @short Action for pasting nodes from clipboard.*/ + KAction* m_pActEditPaste; + + /** Action for editing properties of currently selected node. */ + KAction* m_pActProperties; + + /** Action for editing raw XML of currently selected node. */ + KAction* m_pActEditRawXml; + + /** Action for deleting currently selected node. */ + KAction* m_pActDelete; + + /** @short Action for changing version and encoding of XM file. */ + KAction* m_pActVersionEncoding; + + /** @short Action for attaching stylehseets to xml files. */ + KAction* m_pActAttachStylesheet; + + /** @short Action for detaching stylehseets from xml files. */ + KAction* m_pActDetachStylesheet; + + /** @short Action for attaching schemas to xml files. */ + KAction* m_pActAttachSchema; + + /** @short Action for detaching schemas from xml files. */ + KAction* m_pActDetachSchema; + + /** Printer object. */ + KPrinter *m_pPrinter; + + /** spitter - main widget in the part */ + QSplitter *pSplitter; + + /** Pointer to underlying KXEDocument object */ + KXEDocument* m_pDocument; + +signals: + // Add URL to recent file list + void sigAddRecentURL(const KURL &); +}; + +/** + * The browser extension for our part (@ref KXMLEditorPart). + */ +class KXMLEditorBrowserExtension : public KParts::BrowserExtension +{ + Q_OBJECT + + public: + /** @short Constructor */ + KXMLEditorBrowserExtension( KXMLEditorPart * pParent, const char * pszName = "KXMLEditorBrowserExtension" ) + : KParts::BrowserExtension( pParent, pszName ), + m_pPart(pParent) + { emit enableAction("print", true); } + + public slots: + void slotEditCut() { m_pPart->slotEditCut(); } + void slotEditCopy() { m_pPart->slotEditCopy(); } + void slotEditPaste() { m_pPart->slotEditPaste(); } + void print() { m_pPart->slotActPrint(); } + + protected: + /** @short Stores pointer to the part. */ + KXMLEditorPart * m_pPart; +}; + +#endif + diff --git a/part/kxmleditorpartBrowseUI.rc b/part/kxmleditorpartBrowseUI.rc new file mode 100644 index 0000000..cc939bf --- /dev/null +++ b/part/kxmleditorpartBrowseUI.rc @@ -0,0 +1,81 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui name="kxmleditorpart" version="1"> +<MenuBar> + <Menu name="edit"><text>&Edit</text> + <Separator/> + <Action name="deselect"/> + <Separator/> + <Action name="edit_find"/> + <Action name="edit_find_next"/> + </Menu> + <Menu name="view"><text>&View</text> + <Separator/> + <Action name="treeitem_up"/> + <Action name="treeitem_expand"/> + <Action name="treeitem_collapse"/> + </Menu> + <Menu name="bookmarks"><text>&Bookmarks</text> + <Action name="bookmark_toggle"/> + <Action name="bookmark_prev"/> + <Action name="bookmark_next"/> + </Menu> + <Menu name="settings"><text>&Settings</text> + <Action name="configure"/> + </Menu> +</MenuBar> + +<Menu name="popupXmlElement"> + <Title>XML Element</Title> + <Action name="treeitem_up"/> + <Action name="treeitem_expand"/> + <Action name="treeitem_collapse"/> + <Separator/> + <Action name="deselect"/> + <Separator/> + <Action name="bookmark_toggle"/> +</Menu> + +<Menu name="popupXmlContent"> + <Title>XML Content</Title> + <Action name="treeitem_up"/> + <Separator/> + <Action name="deselect"/> + <Separator/> + <Action name="bookmark_toggle"/> +</Menu> + +<Menu name="popupXmlProcInstr"> + <Title>XML Proc.Instruction</Title> + <Action name="treeitem_up"/> + <Separator/> + <Action name="deselect"/> + <Separator/> + <Action name="bookmark_toggle"/> +</Menu> + +<Menu name="popupXmlTree"> + <Title>XML Tree</Title> + <Action name="deselect"/> +</Menu> + +<ToolBar name="mainToolBar"> + <text>Main Toolbar</text> + <Action name="find"/> + <Separator/> + <Action name="bookmark_toggle"/> + <Action name="bookmark_prev"/> + <Action name="bookmark_next"/> + <Separator/> + <Action name="treeitem_up"/> + <Action name="treeitem_expand"/> + <Action name="treeitem_collapse"/> +</ToolBar> + +<ToolBar fullWidth="true" name="pathToolBar" newline="true"> + <text>Path Toolbar</text> + <Action name="path_clear"/> + <Action name="path_label"/> + <Action name="path_combo"/> +</ToolBar> + +</kpartgui> diff --git a/part/kxmleditorpartEditUI.rc b/part/kxmleditorpartEditUI.rc new file mode 100644 index 0000000..d4f65e1 --- /dev/null +++ b/part/kxmleditorpartEditUI.rc @@ -0,0 +1,186 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui name="kxmleditorpart" version="1"> +<MenuBar> + <Menu name="file"><text>&File</text> + <Action name="file_save" /> + <action name="file_save_as"/> + <Separator lineSeparator="true"/> + <Action name="xml_ins_spec_procins"/> + <Separator lineSeparator="true"/> + <Action name="xml_attach_schema"/> + <Action name="xml_detach_schema"/> + <Action name="xml_attach_stylesheet"/> + <Action name="xml_detach_stylesheet"/> + <Separator lineSeparator="true"/> + <Action name="print"/> + <Separator lineSeparator="true"/> + </Menu> + <Menu name="edit"><text>&Edit</text> + <Action name="edit_undo" group="edit_operations"/> + <Action name="edit_redo" group="edit_operations"/> + <Separator/> + <Action name="edit_cut" group="edit_operations"/> + <Action name="edit_copy" group="edit_operations"/> + <Action name="edit_paste" group="edit_operations"/> + <Separator/> + <Action name="edit_delete" group="edit_operations"/> + <Action name="xml_del_attributes" group="edit_operations"/> + <Separator lineSeparator="true"/> + <Action name="xml_move_item_up"/> + <Action name="xml_move_item_down"/> + <Action name="deselect"/> + <Separator lineSeparator="true"/> + <Action name="edit_find"/> + <Action name="edit_find_next"/> + <Separator lineSeparator="true"/> + <Action name="edit_properties"/> + <Action name="edit_as_raw_xml"/> + </Menu> + <Menu name="view"><text>&View</text> + <Separator/> + <Action name="treeitem_up"/> + <Action name="treeitem_expand"/> + <Action name="treeitem_collapse"/> + </Menu> + <Menu name="insert"><text>&Insert</text> + <Action name="xml_ins_element"/> + <Action name="xml_add_attribute"/> + <Action name="insert_text"/> + <Action name="insert_cdata"/> + <Action name="insert_comment"/> + <Action name="xml_ins_procins"/> + </Menu> + <Menu name="bookmarks"><text>&Bookmarks</text> + <Action name="bookmark_toggle"/> + <Action name="bookmark_prev"/> + <Action name="bookmark_next"/> + </Menu> + <Menu name="settings"><text>&Settings</text> + <Action name="configure"/> + </Menu> + <Merge/> +</MenuBar> + +<Menu name="popupXmlElement"> + <Title>XML Element</Title> + <Action name="edit_properties"/> + <Action name="edit_as_raw_xml"/> + <Separator/> + <Action name="xml_ins_element"/> + <Action name="xml_add_attribute"/> + <Action name="insert_text"/> + <Action name="insert_cdata"/> + <Action name="insert_comment"/> + <Action name="xml_ins_procins"/> + <Separator/> + <Action name="edit_delete"/> + <Action name="xml_del_attributes"/> + <Separator/> + <Action name="xml_move_item_up"/> + <Action name="xml_move_item_down"/> + <Separator/> + <Action name="treeitem_up"/> + <Action name="treeitem_expand"/> + <Action name="treeitem_collapse"/> + <Separator/> + <Action name="deselect"/> + <Separator/> + <Action name="bookmark_toggle"/> +</Menu> + +<Menu name="popupXmlContent"> + <Title>XML Content</Title> + <Action name="edit_properties"/> + <Separator/> + <Action name="xml_move_item_up"/> + <Action name="xml_move_item_down"/> + <Separator/> + <Action name="treeitem_up"/> + <Separator/> + <Action name="edit_delete"/> + <Action name="deselect"/> + <Separator/> + <Action name="bookmark_toggle"/> +</Menu> + +<Menu name="popupXmlProcInstr"> + <Title>XML Proc.Instruction</Title> + <Action name="edit_properties"/> + <Separator/> + <Action name="xml_move_item_up"/> + <Action name="xml_move_item_down"/> + <Separator/> + <Action name="treeitem_up"/> + <Separator/> + <Action name="edit_delete"/> + <Action name="deselect"/> + <Separator/> + <Action name="bookmark_toggle"/> +</Menu> + +<Menu name="popupXmlTree"> + <Title>XML Tree</Title> + <Action name="xml_ins_element"/> + <Action name="xml_ins_procins"/> + <Separator/> + <Action name="deselect"/> +</Menu> + +<Menu name="popupXmlAttribute"> + <Title>XML Attribute</Title> + <Action name="xml_add_attribute"/> + <Separator/> + <Action name="xml_del_attribute"/> +</Menu> + +<Menu name="popupXmlAttributes"> + <Title>XML Attributes</Title> + <Action name="xml_add_attribute"/> +</Menu> + +<ToolBar name="mainToolBar"> + <text>Main Toolbar</text> + <Action name="file_save" group="file_operations" /> + <action name="file_save_as" group="file_operations" /> + <Action name="print" group="file_operations" /> + <Separator/> + <Action name="edit_cut" group="edit_operations" /> + <Action name="edit_copy" group="edit_operations" /> + <Action name="edit_paste" group="edit_operations" /> + <Separator/> + <Action name="edit_undo" group="edit_operations" /> + <Action name="edit_redo" group="edit_operations" /> + <Action name="edit_delete" group="edit_operations" /> + <Action name="edit_find" group="edit_operations" /> + <Separator/> + <Action name="bookmark_toggle"/> + <Action name="bookmark_prev"/> + <Action name="bookmark_next"/> + <Separator/> + <Action name="treeitem_up"/> + <Action name="treeitem_expand"/> + <Action name="treeitem_collapse"/> +</ToolBar> + +<ToolBar fullWidth="true" name="pathToolBar" newline="true"> + <text>Path Toolbar</text> + <Action name="path_clear"/> + <Action name="path_label"/> + <Action name="path_combo"/> +</ToolBar> + +<ToolBar fullWidth="true" name="xmlToolBar" position="left"> + <text>XML Toolbar</text> + <Action name="xml_ins_element"/> + <Action name="xml_add_attribute"/> + <Action name="insert_text"/> + <Action name="insert_cdata"/> + <Action name="insert_comment"/> + <Action name="xml_ins_procins"/> + <Action name="edit_properties"/> + <Separator lineSeparator="true"/> + <Action name="xml_move_item_up"/> + <Action name="xml_move_item_down"/> +</ToolBar> + +</kpartgui> diff --git a/part/pics/Makefile.am b/part/pics/Makefile.am new file mode 100644 index 0000000..a291541 --- /dev/null +++ b/part/pics/Makefile.am @@ -0,0 +1,38 @@ +####### kdevelop will overwrite this part!!! (begin)########## + +EXTRA_DIST = xml_attribute.png xml_cdata.png xml_comment.png xml_element.png xml_text.png xml_procinstr.png xml_cdata_b.png xml_comment_b.png xml_element_b.png xml_text_b.png xml_procinstr_b.png + +install-data-local: + $(mkinstalldirs) $(kde_datadir)/kxmleditor/ + $(mkinstalldirs) $(kde_datadir)/kxmleditor/pics/ + $(INSTALL_DATA) $(srcdir)/xml_attribute.png $(kde_datadir)/kxmleditor/pics/xml_attribute.png + $(INSTALL_DATA) $(srcdir)/xml_cdata.png $(kde_datadir)/kxmleditor/pics/xml_cdata.png + $(INSTALL_DATA) $(srcdir)/xml_contents.png $(kde_datadir)/kxmleditor/pics/xml_contents.png + $(INSTALL_DATA) $(srcdir)/xml_comment.png $(kde_datadir)/kxmleditor/pics/xml_comment.png + $(INSTALL_DATA) $(srcdir)/xml_element.png $(kde_datadir)/kxmleditor/pics/xml_element.png + $(INSTALL_DATA) $(srcdir)/xml_text.png $(kde_datadir)/kxmleditor/pics/xml_text.png + $(INSTALL_DATA) $(srcdir)/xml_procinstr.png $(kde_datadir)/kxmleditor/pics/xml_procinstr.png + $(INSTALL_DATA) $(srcdir)/xml_cdata_b.png $(kde_datadir)/kxmleditor/pics/xml_cdata_b.png + $(INSTALL_DATA) $(srcdir)/xml_contents_b.png $(kde_datadir)/kxmleditor/pics/xml_contents_b.png + $(INSTALL_DATA) $(srcdir)/xml_comment_b.png $(kde_datadir)/kxmleditor/pics/xml_comment_b.png + $(INSTALL_DATA) $(srcdir)/xml_element_b.png $(kde_datadir)/kxmleditor/pics/xml_element_b.png + $(INSTALL_DATA) $(srcdir)/xml_text_b.png $(kde_datadir)/kxmleditor/pics/xml_text_b.png + $(INSTALL_DATA) $(srcdir)/xml_procinstr_b.png $(kde_datadir)/kxmleditor/pics/xml_procinstr_b.png + +uninstall-local: + -rm -f $(kde_datadir)/kxmleditor/pics/xml_attribute.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_cdata.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_contents.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_comment.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_element.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_text.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_procinstr.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_cdata_b.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_contents_b.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_comment_b.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_element_b.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_text_b.png + -rm -f $(kde_datadir)/kxmleditor/pics/xml_procinstr_b.png + -rmdir $(kde_datadir)/kxmleditor/pics + +####### kdevelop will overwrite this part!!! (end)############ diff --git a/part/pics/xml_attribute.png b/part/pics/xml_attribute.png Binary files differnew file mode 100644 index 0000000..56063b0 --- /dev/null +++ b/part/pics/xml_attribute.png diff --git a/part/pics/xml_cdata.png b/part/pics/xml_cdata.png Binary files differnew file mode 100644 index 0000000..69950ea --- /dev/null +++ b/part/pics/xml_cdata.png diff --git a/part/pics/xml_cdata_b.png b/part/pics/xml_cdata_b.png Binary files differnew file mode 100644 index 0000000..42e1b07 --- /dev/null +++ b/part/pics/xml_cdata_b.png diff --git a/part/pics/xml_comment.png b/part/pics/xml_comment.png Binary files differnew file mode 100644 index 0000000..ba37057 --- /dev/null +++ b/part/pics/xml_comment.png diff --git a/part/pics/xml_comment_b.png b/part/pics/xml_comment_b.png Binary files differnew file mode 100644 index 0000000..81fb79d --- /dev/null +++ b/part/pics/xml_comment_b.png diff --git a/part/pics/xml_contents.png b/part/pics/xml_contents.png Binary files differnew file mode 100644 index 0000000..d17730e --- /dev/null +++ b/part/pics/xml_contents.png diff --git a/part/pics/xml_contents_b.png b/part/pics/xml_contents_b.png Binary files differnew file mode 100644 index 0000000..b134b9d --- /dev/null +++ b/part/pics/xml_contents_b.png diff --git a/part/pics/xml_element.png b/part/pics/xml_element.png Binary files differnew file mode 100644 index 0000000..6bd8993 --- /dev/null +++ b/part/pics/xml_element.png diff --git a/part/pics/xml_element_b.png b/part/pics/xml_element_b.png Binary files differnew file mode 100644 index 0000000..88b623b --- /dev/null +++ b/part/pics/xml_element_b.png diff --git a/part/pics/xml_procinstr.png b/part/pics/xml_procinstr.png Binary files differnew file mode 100644 index 0000000..90178b7 --- /dev/null +++ b/part/pics/xml_procinstr.png diff --git a/part/pics/xml_procinstr_b.png b/part/pics/xml_procinstr_b.png Binary files differnew file mode 100644 index 0000000..d854262 --- /dev/null +++ b/part/pics/xml_procinstr_b.png diff --git a/part/pics/xml_text.png b/part/pics/xml_text.png Binary files differnew file mode 100644 index 0000000..fd477a7 --- /dev/null +++ b/part/pics/xml_text.png diff --git a/part/pics/xml_text_b.png b/part/pics/xml_text_b.png Binary files differnew file mode 100644 index 0000000..0fb8946 --- /dev/null +++ b/part/pics/xml_text_b.png diff --git a/part/qdom_add.cpp b/part/qdom_add.cpp new file mode 100644 index 0000000..142b873 --- /dev/null +++ b/part/qdom_add.cpp @@ -0,0 +1,352 @@ +/*************************************************************************** + qdom_add.cpp - description + ------------------- + begin : Wed Nov 21 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. * + * * + ***************************************************************************/ + +/** This file contains useful datatypes and functions in addition to the Qt DOM classes. */ + +#include "qdom_add.h" + +#include <kiconloader.h> +#include <kdebug.h> + +#include <qtextstream.h> + +#include "kxmleditorfactory.h" +#include "kxesearchdialog.h" + +QPixmap g_iconElement( UserIcon("xml_element",KXMLEditorFactory::instance()) ); +QPixmap g_iconText( UserIcon("xml_text",KXMLEditorFactory::instance()) ); +QPixmap g_iconComment( UserIcon("xml_comment",KXMLEditorFactory::instance()) ); +QPixmap g_iconCDATASection( UserIcon("xml_cdata",KXMLEditorFactory::instance()) ); +QPixmap g_iconProcessingInstruction( UserIcon("xml_procinstr",KXMLEditorFactory::instance()) ); +QPixmap g_iconElement_b( UserIcon("xml_element_b",KXMLEditorFactory::instance()) ); +QPixmap g_iconText_b( UserIcon("xml_text_b",KXMLEditorFactory::instance()) ); +QPixmap g_iconComment_b( UserIcon("xml_comment_b",KXMLEditorFactory::instance()) ); +QPixmap g_iconCDATASection_b( UserIcon("xml_cdata_b",KXMLEditorFactory::instance()) ); +QPixmap g_iconProcessingInstruction_b( UserIcon("xml_procinstr_b",KXMLEditorFactory::instance()) ); +QPixmap g_iconUnknown; + +const QPixmap & domTool_getIconForNodeType( QDomNode::NodeType type, bool bBookmarked ) +{ + if(!bBookmarked) + { switch(type) + { case QDomNode::ElementNode: return g_iconElement; break; + case QDomNode::TextNode: return g_iconText; break; + case QDomNode::CDATASectionNode: return g_iconCDATASection; break; + case QDomNode::CommentNode: return g_iconComment; break; + case QDomNode::ProcessingInstructionNode: return g_iconProcessingInstruction; break; + + default: + kdDebug() << "domTool_getIconForNodeType: unknown node type (" << type << ")" << endl; + } + } + else + { switch(type) + { case QDomNode::ElementNode: return g_iconElement_b; break; + case QDomNode::TextNode: return g_iconText_b; break; + case QDomNode::CDATASectionNode: return g_iconCDATASection_b; break; + case QDomNode::CommentNode: return g_iconComment_b; break; + case QDomNode::ProcessingInstructionNode: return g_iconProcessingInstruction_b; break; + + default: + kdDebug() << "domTool_getIconForNodeType: unknown node type (" << type << ")" << endl; + } + } + return g_iconUnknown; +} + +// Obtain XPath for all nodes, instead of elements +QString domTool_getPath( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdDebug() << "domTool_getPath: elelent given" << endl; + return QString(); + } + + if(node.isElement()) + { + kdDebug() << "use domTool_getPath( const QDomElement & domElement ) for elements" << endl; + } + + QString strReturn; + + QDomNode parentNode = node.parentNode(); + if ( (!parentNode.isNull()) && (!parentNode.isDocument()) ) + { + strReturn = domTool_getPath( parentNode.toElement() ); // get the parent's path + strReturn += "/"; // append slash + strReturn += node.nodeName(); // append the given node's name + } + else + strReturn = node.nodeName(); // set the given node's name (must be root element) + + return strReturn; +} + +// Obtain XPath for elements +QString domTool_getPath( const QDomElement & domElement ) +{ + if ( domElement.isNull() ) + { + kdDebug() << "domTool_getPath: no node given" << endl; + return QString(); + } + + QString strReturn; + QDomNode parentNode = domElement.parentNode(); + if ( (!parentNode.isNull()) && (!parentNode.isDocument()) ) + { + // calculate index - only for elements with the same name + int i = 0; + bool bUseIndex = false; // index is used only when exist sibling(s) with the same name + + // traverse previous sibling elements with same name and calculate index + QDomNode tmpNode = domElement.previousSibling(); + while ( ! tmpNode.isNull() ) + { + if(tmpNode.isElement()) + { + QDomElement domSiblingElement = tmpNode.toElement(); + + if(domElement.tagName() == domSiblingElement.tagName()) + { i++; bUseIndex = true; + } + } + tmpNode = tmpNode.previousSibling(); + } + + if(bUseIndex == false) + { + // traverse next sibling elements with same name + // and decide, if index is necessary + QDomNode tmpNode = domElement.nextSibling(); + while ( ! tmpNode.isNull() ) + { + if(tmpNode.isElement()) + { + QDomElement domSiblingElement = tmpNode.toElement(); + + if(domElement.tagName() == domSiblingElement.tagName()) + bUseIndex = true; + } + + tmpNode = tmpNode.nextSibling(); + + } + } + + strReturn = domTool_getPath( parentNode.toElement() ); // get the parent's path + strReturn += "/"; // append slash + strReturn += domElement.nodeName(); // append the given node's name + + if(bUseIndex) + { + QString strIndex; + strIndex.setNum(i+1); + strReturn += "[" + strIndex + "]"; // append the index + } + } + else + strReturn = domElement.nodeName(); // set the given node's name (must be root element) + + return strReturn; +} + +unsigned int domTool_getLevel( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdDebug() << "domTool_getLevel: internal implementation error - the given node is an empty one" << endl; + return 0; + } + + unsigned int iLevel = 0; + QDomNode parentNode = node.parentNode(); + while ( ! parentNode.isNull() ) + { + iLevel++; + parentNode = parentNode.parentNode(); + } + + return iLevel - 1; +} + +QString domTool_save( const QDomNode & node, int iIndent ) +{ + QString strXML; + QTextStream ts( & strXML, IO_WriteOnly ); + + node.save(ts, iIndent); + return strXML; +} + +QDomNode domTool_prevNode( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdDebug() << "domTool_prevNode: internal implementation error - the given node is an empty one" << endl; + return QDomNode(); + } + + if ( ! node.previousSibling().isNull() ) // if there is a prev. sibling + { // return its last grand child (if there is any) + QDomNode prevNode = node.previousSibling(); + while ( ! prevNode.lastChild().isNull() ) + prevNode = prevNode.lastChild(); + return prevNode; + } + else // if there is no prev. sibling, return + return node.parentNode(); // the nodes parent (if there is any) + +} + +QDomNode domTool_nextNode( const QDomNode & node ) +{ + if ( node.isNull() ) + { + kdDebug() << "domTool_nextNode: internal implementation error - the given node is an empty one" << endl; + return QDomNode(); + } + + // checking for a child + if ( ! node.firstChild().isNull() ) + return node.firstChild(); + + // there is no child -> checking for the next sibling + if ( ! node.nextSibling().isNull() ) + return node.nextSibling(); + + // there is no next sibling -> checking for parents' next sibling(s) + QDomNode nodeParent = node.parentNode(); + while ( ! nodeParent.isNull() ) + { + if ( ! nodeParent.nextSibling().isNull() ) + return nodeParent.nextSibling(); + + nodeParent = nodeParent.parentNode(); // parent has no sibling - try its parent + } + + // parent has no parents anymore + return QDomNode(); // return empty node +} + +QDomNode domTool_matchingNode( const QDomNode & node, const QString & szPath ) +{ + if(szPath.length() == 0) + return QDomNode(); // return void node + + QString szNodePath = node.isDocument() ? QString("") : domTool_getPath(node); + if ( szPath == szNodePath ) // test if the strings match + return node; + + /* L.V. those optimalizations disallow find proc. instr. at doc. level + + // we will find any node in root element subtree + if ( szPath.length() <= szNodePath.length() ) // the given string must be longer + return QDomNode(); // otherwise we don't need to check the childs + + if ( szPath.left(szNodePath.length()) != szNodePath ) // the nodes path must be left part of the given path + return QDomNode(); // otherwise we don't need to check the childs + */ + + // recursively check the childs + QDomNode nodeChild = node.firstChild(); + QDomNode nodeTmp; + while ( ! nodeChild.isNull() ) + { + nodeTmp = domTool_matchingNode( nodeChild, szPath ); + if ( ! nodeTmp.isNull() ) + return nodeTmp; + nodeChild = nodeChild.nextSibling(); + } + + return QDomNode(); // nothing found -> return empty node +} + +bool domTool_match( QDomNode node, const KXESearchDialog * const pConditions ) +{ + if ( node.isNull() ) + { + kdDebug() << "domTool_match: internal implementation error - the given node is an empty one" << endl; + return false; + } + + if ( ! pConditions ) + { + kdDebug() << "domTool_match: internal implementation error - the given pointer is a null pointer" << endl; + return false; + } + + switch ( node.nodeType() ) + { + case QDomNode::ElementNode: // ---------------------------------------- + { + if ( pConditions->getInElementNames() ) + { + if ( node.toElement().tagName().find( pConditions->getSearchString(), 0, pConditions->getMatchCase() ) >= 0 ) + return true; + } + + if ( ( pConditions->getInAttributeNames() ) || ( pConditions->getInAttributeValues() ) ) + { + QDomNamedNodeMap list = node.toElement().attributes(); + unsigned int iLength = list.length(); + if ( iLength <= 0 ) + return false; // no attributes + + for ( unsigned int iRow = 0; iRow < iLength; iRow++ ) + { + if ( pConditions->getInAttributeNames() ) + if ( list.item(iRow).toAttr().name().find( pConditions->getSearchString(), 0, pConditions->getMatchCase() ) >= 0 ) + return true; + if ( pConditions->getInAttributeValues() ) + if ( list.item(iRow).toAttr().value().find( pConditions->getSearchString(), 0, pConditions->getMatchCase() ) >= 0 ) + return true; + } + return false; + } + + return false; + break; + } + + case QDomNode::TextNode: // ---------------------------------------- + case QDomNode::CDATASectionNode: + case QDomNode::CommentNode: + { + if ( pConditions->getInContents() ) + { + if ( node.toCharacterData().data().find( pConditions->getSearchString(), 0, pConditions->getMatchCase() ) >= 0 ) + return true; + else + return false; + } + else + return false; + + break; + } + +// TODO implement this for the other node types (eg proc.instr.) + + default: + kdDebug() << "domTool_match: unknown node type (" << node.nodeType() << ")" << endl; + } + + return true; +} + diff --git a/part/qdom_add.h b/part/qdom_add.h new file mode 100644 index 0000000..4e9634c --- /dev/null +++ b/part/qdom_add.h @@ -0,0 +1,80 @@ +/*************************************************************************** + qdom_add.h - description + ------------------- + begin : Wed Nov 21 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 QDOM_ADD_H +#define QDOM_ADD_H + +/** This file contains useful datatypes and functions in addition to the Qt DOM classes. */ + +#include <qpixmap.h> +#include <qdom.h> + +class KXESearchDialog; + +extern QPixmap g_iconElement; +extern QPixmap g_iconText; +extern QPixmap g_iconComment; +extern QPixmap g_iconCDATASection; +extern QPixmap g_iconProcessingInstruction; +extern QPixmap g_iconElement_b; +extern QPixmap g_iconText_b; +extern QPixmap g_iconComment_b; +extern QPixmap g_iconCDATASection_b; +extern QPixmap g_iconProcessingInstruction_b; + +/** Returns the corresponding pixmap/icon to the given node type. */ +const QPixmap & domTool_getIconForNodeType( QDomNode::NodeType type, bool ); + +/** Returns the path of the given node. */ +QString domTool_getPath( const QDomNode & ); + +/** Returns the path of the given node. */ +QString domTool_getPath( const QDomElement & ); + +/** Returns the level (how deep in tree) of the given node. */ +unsigned int domTool_getLevel( const QDomNode & ); + +/** Returns a QString with the XML representation of the given node including all its children (uses @ref QDomNode::save). */ +QString domTool_save( const QDomNode &, int ); + +/** + * Returns the previous node of the given one or an empty node, if it is the first. + * This will be its previous siblings last grand child, if there is one. + * Otherwise it is the previous sibling or, + * if there is no sibling above, it will be its parent or + * an empty node (if there is no parent). + */ +QDomNode domTool_prevNode( const QDomNode & node ); +/** + * Returns the next node of the given one or an empty node, if it is the last. + * This will be it's first child, + * if there are no childs, it will be the next sibling + * and if there are no siblings below, it will be the parent's next sibling ... + */ +QDomNode domTool_nextNode( const QDomNode & node ); + +/** + * Tests the given node and its (grand)childs. + * Returns the node, which matches the given path, oran empty node (if no one matches). + */ +QDomNode domTool_matchingNode( const QDomNode & node, const QString & szPath ); + +/** Tests, if the given node matches the conditions of the given search. */ +bool domTool_match( QDomNode node, const KXESearchDialog * const pConditions ); + +#endif + |