|
View:
New views
12 Messages
—
Rating Filter:
Alert me
|
|
|
HighlightInterfaceHi,
after discussions with Milian and Christoph we came up with this: HighlightInterface: // make default styles available - enum: DefaultStyles ... all katepart default styles - Attribute defaultStyle(DefaultStyle ds); // dsNormalText, ..., dsError // get attribute list of complete line (already in KateTextLine) - QVector<KTE::HighlightInterface::AttributeBlock> lineAttributes(int line) const; AttributeBlock: int: start int: length Attribute: attribute // get mode at cursor position - QString modeAt(const KTE::Cursor& position) const; // get all modes in document - QStringList modes() const; ConfigIterface for KTE::View // query background colors - value: background-color -> QVariant - value: background-selection-color -> QVariant Note: has nothing to do with Highlight interface, as it's global // emit signal when highlight or config stuff changed - signal: emit configChanged(), whenever configEnd is called in the KateViewConfig Cheers, Dominik _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceOn Wednesday 21 October 2009 23:09:43 Dominik Haumann wrote:
... > ConfigIterface for KTE::View ... > // emit signal when highlight or config stuff changed > - signal: emit configChanged(), whenever configEnd is called in the > KateViewConfig Finally started with this, so I can finish it in time for 4.4. One question: How do I define a Signal in an Interface? I probably don't want Q_SIGNALS: configChanged(); Or do I? I mean slots are implemented as pure virtuals and I'm not sure... Oh and one more thing - should I include a: private: class HighlightInterfacePrivate* const d; The config interface does that even though it's also pure virtual... So I think "yes" is the correct answer? :) -- Milian Wolff mail@... http://milianw.de _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceOn Wednesday 21 October 2009 23:09:43 Dominik Haumann wrote:
> Hi, > > after discussions with Milian and Christoph we came up with this: > > HighlightInterface: .... > // get all modes in document > - QStringList modes() const; Will change this to "embeddedModes()" as modes() is already takin for the (afaik un-i18n-ed?) names of all available highlighting modes. Do we also need something similar to highlightingMode, i.e. the i18n name? -- Milian Wolff mail@... http://milianw.de _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceOn 11.11.09 00:55:11, Milian Wolff wrote:
> On Wednesday 21 October 2009 23:09:43 Dominik Haumann wrote: > ... > > > ConfigIterface for KTE::View > ... > > // emit signal when highlight or config stuff changed > > - signal: emit configChanged(), whenever configEnd is called in the > > KateViewConfig > > Finally started with this, so I can finish it in time for 4.4. > > One question: How do I define a Signal in an Interface? I probably don't want > > Q_SIGNALS: > configChanged(); > > Or do I? I mean slots are implemented as pure virtuals and I'm not sure... Signals can be done as pure virtuals too, so whoever writes an implementation of the interface is told by the compiler if he forgot the signal. Unfortunately there's no way to declare signals on interfaces as moc won't create the needed code. See also other KTE interfaces that have signals, for example KTE::MarkInterface. > Oh and one more thing - should I include a: > > private: > class HighlightInterfacePrivate* const d; > > The config interface does that even though it's also pure virtual... So I think > "yes" is the correct answer? :) No is the correct answer, unless the interface needs private members or private functions. And a pure interface shouldn't need either. Andreas -- You're being followed. Cut out the hanky-panky for a few days. _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceOn Wednesday 11 November 2009 09:52:43 Andreas Pakulat wrote:
> On 11.11.09 00:55:11, Milian Wolff wrote: > > On Wednesday 21 October 2009 23:09:43 Dominik Haumann wrote: > > ... > > > > > ConfigIterface for KTE::View > > > > ... > > > > > // emit signal when highlight or config stuff changed > > > - signal: emit configChanged(), whenever configEnd is called in the > > > KateViewConfig > > > > Finally started with this, so I can finish it in time for 4.4. > > > > One question: How do I define a Signal in an Interface? I probably don't > > want > > > > Q_SIGNALS: > > configChanged(); > > > > Or do I? I mean slots are implemented as pure virtuals and I'm not > > sure... > > Signals can be done as pure virtuals too, so whoever writes an > implementation of the interface is told by the compiler if he forgot the > signal. Unfortunately there's no way to declare signals on interfaces as > moc won't create the needed code. See also other KTE interfaces that > have signals, for example KTE::MarkInterface. article I'd say it's not. I'd rather than document the signal but not insert the pure virtual. Emitting & connecting can take place anyways. What is your opinion? > > Oh and one more thing - should I include a: > > > > private: > > class HighlightInterfacePrivate* const d; > > > > The config interface does that even though it's also pure virtual... So I > > think "yes" is the correct answer? :) > > No is the correct answer, unless the interface needs private members or > private functions. And a pure interface shouldn't need either. -- Milian Wolff mail@... http://milianw.de _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceOn 11.11.09 11:26:52, Milian Wolff wrote:
> On Wednesday 11 November 2009 09:52:43 Andreas Pakulat wrote: > > On 11.11.09 00:55:11, Milian Wolff wrote: > > > On Wednesday 21 October 2009 23:09:43 Dominik Haumann wrote: > > > ... > > > > > > > ConfigIterface for KTE::View > > > > > > ... > > > > > > > // emit signal when highlight or config stuff changed > > > > - signal: emit configChanged(), whenever configEnd is called in the > > > > KateViewConfig > > > > > > Finally started with this, so I can finish it in time for 4.4. > > > > > > One question: How do I define a Signal in an Interface? I probably don't > > > want > > > > > > Q_SIGNALS: > > > configChanged(); > > > > > > Or do I? I mean slots are implemented as pure virtuals and I'm not > > > sure... > > > > Signals can be done as pure virtuals too, so whoever writes an > > implementation of the interface is told by the compiler if he forgot the > > signal. Unfortunately there's no way to declare signals on interfaces as > > moc won't create the needed code. See also other KTE interfaces that > > have signals, for example KTE::MarkInterface. > > But this is not BC compatible, is it? At least according to the Techbase > article I'd say it's not. If you want to change an existing interface, no. With such an interface class you basically can't do anything. > I'd rather than document the signal but not insert the pure virtual. Emitting > & connecting can take place anyways. Right. Emitting and connecting only happens on the actual object with the implementation. You might get warnings from gcc about hiding the original method. Andreas -- You'll never see all the places, or read all the books, but fortunately, they're not all recommended. _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceHi!
Signals do not have to be virtual. They use their own dispatching-method generated by moc. Signals are not parts of the normal interface- implementation-model, declare them like in all the other classes. (signals: void bla(); ) And don't forget: In C++ Interfaces are like any other class: They need space in the object-layout, make this-pointer adjustments necessary..., and you can declare anything in the Interface. The Interface should not contain private data and HighlightInterfacePrivate should not exist because polymorphism for such a class would be useless. Let the implementation decide how to save information. The User ------------------------ Automatisch eingefügte Signatur: Es lebe die Freiheit! Stoppt den Gebrauch proprietärer Software! Operating System: GNU/Linux Kernel: Linux 2.6.31-ARCH Distribution: Arch Linux Qt: 4.6.0 KDE: 4.3.73 (KDE 4.3.73 (KDE 4.4 >= 20091026)) KMail: 1.12.90 http://gnu.org/ http://kde.org/ http://windows7sins.org/ _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceOn Wednesday 11 November 2009 20:57:12 Jonathan Schmidt-Dominé - Developer
wrote: > Hi! > > Signals do not have to be virtual. They use their own dispatching-method > generated by moc. Signals are not parts of the normal interface- > implementation-model, declare them like in all the other classes. (signals: > void bla(); ) > And don't forget: In C++ Interfaces are like any other class: They need > space in the object-layout, make this-pointer adjustments necessary..., > and you can declare anything in the Interface. > The Interface should not contain private data and HighlightInterfacePrivate > should not exist because polymorphism for such a class would be useless. > Let the implementation decide how to save information. "real" signal. The other interfaces really do use pure virtuals, which is out of the question for the ConfigInterface as it would break BC. I'll just document it and mark it as TODO for KDE 5 *sigh*. -- Milian Wolff mail@... http://milianw.de _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceOn Wednesday 21 October 2009 23:09:43 Dominik Haumann wrote:
> Hi, > > after discussions with Milian and Christoph we came up with this: > > HighlightInterface: > // make default styles available > - enum: DefaultStyles ... all katepart default styles > - Attribute defaultStyle(DefaultStyle ds); // dsNormalText, ..., dsError > > // get attribute list of complete line (already in KateTextLine) > - QVector<KTE::HighlightInterface::AttributeBlock> lineAttributes(int > line) const; AttributeBlock: > int: start > int: length > Attribute: attribute > > // get mode at cursor position > - QString modeAt(const KTE::Cursor& position) const; > > // get all modes in document > - QStringList modes() const; > > > > ConfigIterface for KTE::View > // query background colors > - value: background-color -> QVariant > - value: background-selection-color -> QVariant > Note: has nothing to do with Highlight interface, as it's global > // emit signal when highlight or config stuff changed > - signal: emit configChanged(), whenever configEnd is called in the > KateViewConfig 1) the highlight interface, it's implementation, and the porting of the HTML Exporter to a real plugin to show that the interface works. Note: modes() -> embeddedModes() returns all possible embedded modes, not the default Document::mode() Note: lineAttributes returns a QList, since I added a ctor to the AttributeBlock and hence QVector could not be used. If this is an issue, tell me and I'll revert. (I just hate structs with no ctor personally :P) Also note that the attributes that are returned don't have to span the whole line. Areas where no highlighting is done, are not covered by the AttributeBlock. If this should change, tell me. Note: I pushed the whole DefaultStyle enum into the interface and used it across Kate, i.e. the enum from KateExtendedAttribute is gone. Note: To implement defaultStyle I pushed some code from the KateHLManager to its own method so it can be reused easily. But in this method I get the KColorScheme everytime the method is called. If this is too slow, tell me and I'll work around it. Note: modeAt() returns Document::mode() as a fall-back, should work nicely. 2) the background-color & selection-color note that I called it this way since it's how it was called in KateView 3) one for the signal (only documented in the interface, and implemented in document & view). Please review, test and give feedback! Especially the -- Milian Wolff mail@... http://milianw.de [colorconfig.patch] diff --git a/interfaces/ktexteditor/configinterface.h b/interfaces/ktexteditor/configinterface.h index d2c9faa..f2943f6 100644 --- a/interfaces/ktexteditor/configinterface.h +++ b/interfaces/ktexteditor/configinterface.h @@ -67,6 +67,8 @@ namespace KTextEditor * - line-numbers [bool], show/hide line numbers * - icon-bar [bool], show/hide icon bar * - dynamic-word-wrap [bool], enable/disable dynamic word wrap + * - background-color [QColor], read/set the default background color + * - selection-color [QColor], read/set the default color for selections * * KTextEditor::Document has support for the following: * - auto-brackets [bool], enable/disable automatic bracket completion diff --git a/kate/view/kateview.cpp b/kate/view/kateview.cpp index a6b1b51..587f13f 100644 --- a/kate/view/kateview.cpp +++ b/kate/view/kateview.cpp @@ -2578,7 +2578,8 @@ void KateView::aboutToShowContextMenu( ) // BEGIN ConfigInterface stff QStringList KateView::configKeys() const { - return QStringList() << "icon-bar" << "line-numbers" << "dynamic-word-wrap"; + return QStringList() << "icon-bar" << "line-numbers" << "dynamic-word-wrap" + << "background-color" << "selection-color"; } QVariant KateView::configValue(const QString &key) @@ -2589,6 +2590,10 @@ QVariant KateView::configValue(const QString &key) return config()->lineNumbers(); else if (key == "dynamic-word-wrap") return config()->dynWordWrap(); + else if (key == "background-color") + return renderer()->config()->backgroundColor(); + else if (key == "selection-color") + return renderer()->config()->selectionColor(); // return invalid variant return QVariant(); @@ -2596,17 +2601,16 @@ QVariant KateView::configValue(const QString &key) void KateView::setConfigValue(const QString &key, const QVariant &value) { - // We can only get away with this right now because there are no - // non-bool functions here.. change this later if you are adding - // a config option which uses variables other than bools.. - bool toggle = value.toBool(); - if (key == "icon-bar") - config()->setIconBar(toggle); + config()->setIconBar(value.toBool()); else if (key == "line-numbers") - config()->setLineNumbers(toggle); + config()->setLineNumbers(value.toBool()); else if (key == "dynamic-word-wrap") - config()->setDynWordWrap(toggle); + config()->setDynWordWrap(value.toBool()); + else if (key == "background-color") + renderer()->config()->setBackgroundColor(value.value<QColor>()); + else if (key == "selection-color") + renderer()->config()->setSelectionColor(value.value<QColor>()); } // END ConfigInterface [configchanged.patch] diff --git a/interfaces/ktexteditor/configinterface.h b/interfaces/ktexteditor/configinterface.h index f2943f6..6e65c48 100644 --- a/interfaces/ktexteditor/configinterface.h +++ b/interfaces/ktexteditor/configinterface.h @@ -77,6 +77,9 @@ namespace KTextEditor * - backup-on-save-suffix [string], set the suffix for file backups, e.g. "~" * - backup-on-save-prefix [string], set the prefix for file backups, e.g. "." * + * Either interface should emit the \p configChanged signal when appropriate. + * TODO: Add to interface in KDE 5. + * * For instance, if you want to enable dynamic word wrap of a KTextEditor::View * simply call * \code diff --git a/kate/document/katedocument.cpp b/kate/document/katedocument.cpp index 09bcffb..3bc46f1 100644 --- a/kate/document/katedocument.cpp +++ b/kate/document/katedocument.cpp @@ -4103,6 +4103,8 @@ void KateDocument::updateConfig () if(m_onTheFlyChecker) { m_onTheFlyChecker->updateConfig(); } + + emit configChanged(); } //BEGIN Variable reader diff --git a/kate/document/katedocument.h b/kate/document/katedocument.h index b2c2b14..f189bce 100644 --- a/kate/document/katedocument.h +++ b/kate/document/katedocument.h @@ -451,6 +451,9 @@ class KateDocument : public KTextEditor::Document, void readSessionConfig (const KConfigGroup&); void writeSessionConfig (KConfigGroup&); + Q_SIGNALS: + void configChanged(); + // // KTextEditor::MarkInterface // diff --git a/kate/view/kateview.cpp b/kate/view/kateview.cpp index 587f13f..931c144 100644 --- a/kate/view/kateview.cpp +++ b/kate/view/kateview.cpp @@ -1501,6 +1501,8 @@ void KateView::updateConfig () } tagAll (); updateView (true); + + emit configChanged(); } void KateView::updateDocumentConfig() diff --git a/kate/view/kateview.h b/kate/view/kateview.h index 4c07860..0ef1d74 100644 --- a/kate/view/kateview.h +++ b/kate/view/kateview.h @@ -177,6 +177,9 @@ class KateView : public KTextEditor::View, QVariant configValue(const QString &key); void setConfigValue(const QString &key, const QVariant &value); + Q_SIGNALS: + void configChanged(); + // // KTextEditor::CodeCompletionInterface2 // [highlightinterface.patch] diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index a4f86c9..0ddfaf4 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -855,6 +855,7 @@ install( FILES KTextEditor/Editor KTextEditor/EditorChooser KTextEditor/Factory + KTextEditor/HighlightInterface KTextEditor/MarkInterface KTextEditor/ModificationInterface KTextEditor/Plugin diff --git a/includes/KTextEditor/HighlightInterface b/includes/KTextEditor/HighlightInterface new file mode 100644 index 0000000..f76307f --- /dev/null +++ b/includes/KTextEditor/HighlightInterface @@ -0,0 +1 @@ +#include "../../ktexteditor/highlightinterface.h" diff --git a/interfaces/ktexteditor/CMakeLists.txt b/interfaces/ktexteditor/CMakeLists.txt index 8d2176a..b13b910 100644 --- a/interfaces/ktexteditor/CMakeLists.txt +++ b/interfaces/ktexteditor/CMakeLists.txt @@ -18,6 +18,7 @@ set(ktexteditor_LIB_SRCS codecompletionmodelcontrollerinterface.cpp configinterface.cpp smartinterface.cpp + highlightinterface.cpp ) @@ -71,6 +72,7 @@ install( FILES containerinterface.h annotationinterface.h loadsavefiltercheckplugin.h + highlightinterface.h DESTINATION ${INCLUDE_INSTALL_DIR}/ktexteditor COMPONENT Devel) install( FILES ktexteditor.desktop ktexteditorplugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) diff --git a/interfaces/ktexteditor/highlightinterface.cpp b/interfaces/ktexteditor/highlightinterface.cpp new file mode 100644 index 0000000..1fce2de --- /dev/null +++ b/interfaces/ktexteditor/highlightinterface.cpp @@ -0,0 +1,32 @@ +/* This file is part of the KDE project + Copyright (C) 2009 Milian Wolff <mail@...> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "highlightinterface.h" + +using namespace KTextEditor; + +HighlightInterface::HighlightInterface () +{ +} + +HighlightInterface::~HighlightInterface() +{ +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/interfaces/ktexteditor/highlightinterface.h b/interfaces/ktexteditor/highlightinterface.h new file mode 100644 index 0000000..09d444b --- /dev/null +++ b/interfaces/ktexteditor/highlightinterface.h @@ -0,0 +1,161 @@ +/* This file is part of the KDE project + Copyright (C) 2009 Milian Wolff <mail@...> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KDELIBS_KTEXTEDITOR_HIGHLIGHTINTERFACE_H +#define KDELIBS_KTEXTEDITOR_HIGHLIGHTINTERFACE_H + +#include <ktexteditor/ktexteditor_export.h> + +#include <ktexteditor/attribute.h> +#include <ktexteditor/cursor.h> + +namespace KTextEditor +{ + +class Document; + +/** + * \brief Highlighting information interface for the Document. + * + * \ingroup kte_group_doc_extensions + * + * \section highlightiface_intro Introduction + * + * The HighlightInterface provides methods to access the Attributes + * used for highlighting the Document. + * + * \section searchiface_access Accessing the HighlightInterface + * + * The HighlightInterface is supposed to be an extension interface for a + * Document, i.e. the Document inherits the interface \e provided that the + * used KTextEditor library implements the interface. Use qobject_cast to + * access the interface: + * \code + * // doc is of type KTextEditor::Document* + * KTextEditor::HighlightInterface *iface = + * qobject_cast<KTextEditor::HighlightInterface*>( doc ); + * + * if( iface ) { + * // the implementation supports the interface + * // do stuff + * } + * \endcode + * + * \see KTextEditor::Document + * \author Milian Wolff \<mail@...\> + */ +class KTEXTEDITOR_EXPORT HighlightInterface +{ + public: + ///TODO: Documentation + enum DefaultStyle { + dsNormal, + dsKeyword, + dsDataType, + dsDecVal, + dsBaseN, + dsFloat, + dsChar, + dsString, + dsComment, + dsOthers, + dsAlert, + dsFunction, + dsRegionMarker, + dsError + }; + + /** + * Constructor. + */ + HighlightInterface(); + + /** + * Virtual destructor. + */ + virtual ~HighlightInterface(); + + /** + * Returns the attribute used for the style \p ds. + */ + virtual Attribute::Ptr defaultStyle(const DefaultStyle ds) const = 0; + + /// An AttributeBlock represents an Attribute with its + /// dimension in a given line. + /// + /// \see lineAttributes() + struct AttributeBlock { + AttributeBlock(const int _start, const int _length, const Attribute::Ptr & _attribute) + : start(_start), length(_length), attribute(_attribute) + { + } + /// The column this attribute starts at. + int start; + /// The number of columns this attribute spans. + int length; + /// The attribute for the current range. + Attribute::Ptr attribute; + }; + + /** + * Get the list of AttributeBlocks for a given \p line in the document. + * + * \return List of AttributeBlocks for given \p line. + * + * TODO: I intended to make this const but Kate's implementation needs to + * call kateTextline which is non-const. Solution? + * TODO: Cannot be QVector since we have a CTor. Should it be removed? + */ + virtual QList<AttributeBlock> lineAttributes(const unsigned int line) = 0; + + /** + * \brief Get all available highlighting modes for the current document. + * + * Each document can be highlighted using an arbitrary number of highlighting + * contexts. This method will return the names for each of the used modes. + * + * Example: The "PHP (HTML)" mode includes the highlighting for PHP, HTML, CSS and JavaScript. + * + * \return Returns a list of embedded highlighting modes for the current Document. + * + * \see KTextEditor::Document::mode() + */ + virtual QStringList embeddedModes() const = 0; + + /** + * \brief Get the highlight mode used at a given position in the document. + * + * Retrieve the name of the applied highlight mode at a given \p position + * in the current document. + * + * \see modes() + * + * TODO: I intended to make this const but Kate's implementation needs to + * call kateTextline which is non-const. Solution? + */ + virtual QString modeAt(const Cursor &position) = 0; +}; + +} + +Q_DECLARE_INTERFACE(KTextEditor::HighlightInterface, "org.kde.KTextEditor.HighlightInterface") + +#endif // KDELIBS_KTEXTEDITOR_HIGHLIGHTINTERFACE_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/CMakeLists.txt b/kate/CMakeLists.txt index 3377371..391501d 100644 --- a/kate/CMakeLists.txt +++ b/kate/CMakeLists.txt @@ -159,7 +159,6 @@ utils/katedynamicanimation.cpp utils/katestyletreewidget.cpp utils/katepartpluginmanager.cpp utils/katehistorymodel.cpp -utils/katehtmlexporter.cpp ) diff --git a/kate/data/CMakeLists.txt b/kate/data/CMakeLists.txt index 5d4ef15..14fdba3 100644 --- a/kate/data/CMakeLists.txt +++ b/kate/data/CMakeLists.txt @@ -1,4 +1,3 @@ install( FILES katepartui.rc katepartsimpleui.rc DESTINATION ${DATA_INSTALL_DIR}/katepart ) -install( FILES katepart_htmlexporterui.rc DESTINATION ${DATA_INSTALL_DIR}/katepart ) install( FILES katepart.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) -install( FILES katemoderc DESTINATION ${CONFIG_INSTALL_DIR} ) \ No newline at end of file +install( FILES katemoderc DESTINATION ${CONFIG_INSTALL_DIR} ) diff --git a/kate/data/katepart_htmlexporterui.rc b/kate/data/katepart_htmlexporterui.rc deleted file mode 100644 index 933f843..0000000 --- a/kate/data/katepart_htmlexporterui.rc +++ /dev/null @@ -1,14 +0,0 @@ -<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> -<gui name="katepart_htmlexporter" library="katepart" version="1"> - -<MenuBar> - <Menu name="file" noMerge="1"><text>&File</text> - <Action name="file_export_html" group="print_merge"/> - </Menu> - - <Menu name="edit" noMerge="1"><text>&Edit</text> - <Action name="edit_copy_html" group="edit_paste_merge" /> - </Menu> -</MenuBar> - -</gui> diff --git a/kate/document/katedocument.cpp b/kate/document/katedocument.cpp index 6c6be3f..09bcffb 100644 --- a/kate/document/katedocument.cpp +++ b/kate/document/katedocument.cpp @@ -5486,4 +5486,65 @@ void KateDocument::replaceCharactersByEncoding(const KTextEditor::Range& range) } } +// +// KTextEditor::HighlightInterface +// + +KTextEditor::Attribute::Ptr KateDocument::defaultStyle(const KTextEditor::HighlightInterface::DefaultStyle ds) const +{ + return KateHlManager::self()->getDefaultAttribute(ds); +} + +QList< KTextEditor::HighlightInterface::AttributeBlock > KateDocument::lineAttributes(const unsigned int line) +{ + ///TODO: should this maybe be put into the View until the glory day the renderer does not require a View? + + QList< KTextEditor::HighlightInterface::AttributeBlock > attribs; + + KateView* view = activeKateView(); + Q_ASSERT(view); + + KateTextLine::Ptr kateLine = kateTextLine(line); + + if ( !kateLine ) { + return attribs; + } + + const QVector<int> & intAttrs = kateLine->attributesList(); + + Q_ASSERT(intAttrs.size() % 3 == 0); + + for ( int i = 0; i < intAttrs.size(); i += 3 ) { + attribs << KTextEditor::HighlightInterface::AttributeBlock( + intAttrs[i], + intAttrs[i+1], + view->renderer()->attribute(intAttrs[i+2]) + ); + } + + return attribs; +} + +QStringList KateDocument::embeddedModes() const +{ + return highlight()->getEmbeddedModes(); +} + +QString KateDocument::modeAt(const KTextEditor::Cursor& position) +{ + KateTextLine::Ptr kateLine = kateTextLine(position.line()); + + const QVector<int> & intAttrs = kateLine->attributesList(); + + Q_ASSERT(intAttrs.size() % 3 == 0); + + for ( int i = 0; i < intAttrs.size(); i += 3 ) { + if ( intAttrs[i] <= position.column() && intAttrs[i] + intAttrs[i+1] > position.column() ) { + return KateHlManager::self()->nameForIdentifier(highlight()->hlKeyForAttrib(intAttrs[i+2])); + } + } + + return mode(); +} + // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/document/katedocument.h b/kate/document/katedocument.h index bf188b9..b2c2b14 100644 --- a/kate/document/katedocument.h +++ b/kate/document/katedocument.h @@ -41,6 +41,7 @@ #include <ktexteditor/rangefeedback.h> #include <ktexteditor/configinterface.h> #include <ktexteditor/annotationinterface.h> +#include <ktexteditor/highlightinterface.h> #include "katetextline.h" #include "katenamespace.h" @@ -77,7 +78,8 @@ class KateDocument : public KTextEditor::Document, public KTextEditor::ConfigInterface, public KTextEditor::SmartInterface, private KTextEditor::SmartRangeWatcher, - public KTextEditor::AnnotationInterface + public KTextEditor::AnnotationInterface, + public KTextEditor::HighlightInterface { Q_OBJECT Q_INTERFACES(KTextEditor::SessionConfigInterface) @@ -88,6 +90,7 @@ class KateDocument : public KTextEditor::Document, Q_INTERFACES(KTextEditor::SmartInterface) Q_INTERFACES(KTextEditor::AnnotationInterface) Q_INTERFACES(KTextEditor::ConfigInterface) + Q_INTERFACES(KTextEditor::HighlightInterface) public: explicit KateDocument (bool bSingleViewMode=false, bool bBrowserView=false, bool bReadOnly=false, @@ -1045,6 +1048,15 @@ class KateDocument : public KTextEditor::Document, virtual bool insertTemplateTextImplementation ( const KTextEditor::Cursor &c, const QString &templateString, const QMap<QString,QString> &initialValues, QWidget *); + // + // KTextEditor::HighlightInterface + // + public: + virtual KTextEditor::Attribute::Ptr defaultStyle(const KTextEditor::HighlightInterface::DefaultStyle ds) const; + virtual QList< KTextEditor::HighlightInterface::AttributeBlock > lineAttributes(const unsigned int line); + virtual QStringList embeddedModes() const; + virtual QString modeAt(const KTextEditor::Cursor& position); + protected Q_SLOTS: void dumpRegionTree(); diff --git a/kate/plugins/CMakeLists.txt b/kate/plugins/CMakeLists.txt index c088169..8795427 100644 --- a/kate/plugins/CMakeLists.txt +++ b/kate/plugins/CMakeLists.txt @@ -3,6 +3,8 @@ include_directories( ${KDE4_KIO_INCLUDES} ) add_subdirectory( insertfile ) add_subdirectory( kdatatool ) add_subdirectory( pythonencoding ) +add_subdirectory( exporter ) + # This plugin is for howto-write-a-plugin purposes. It is not meant to be # installed. If you want to do so, just uncomment the add_subdirectory line. # diff --git a/kate/plugins/exporter/CMakeLists.txt b/kate/plugins/exporter/CMakeLists.txt new file mode 100644 index 0000000..b6b4b59 --- /dev/null +++ b/kate/plugins/exporter/CMakeLists.txt @@ -0,0 +1,26 @@ +project( ktexteditor_exporter ) + +find_package( KDE4 REQUIRED ) +include( KDE4Defaults ) + +########### next target ############### + +include_directories( ${KDE4_INCLUDES} ${QT_INCLUDES} ) +add_definitions( ${QT_DEFINITIONS} ${KDE4_DEFINITIONS} ) + +set( ktexteditor_exporter_PART_SRCS + exporterplugin.cpp + exporterpluginview.cpp + htmlexporter.cpp +) + +kde4_add_plugin( ktexteditor_exporter ${ktexteditor_exporter_PART_SRCS} ) + +target_link_libraries( ktexteditor_exporter ${KDE4_KDECORE_LIBS} ${KDE4_KTEXTEDITOR_LIBS} ) + +install( TARGETS ktexteditor_exporter DESTINATION ${PLUGIN_INSTALL_DIR} ) + +########### install files ############### + +install( FILES ktexteditor_exporter.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) +install( FILES ktexteditor_exporterui.rc DESTINATION ${DATA_INSTALL_DIR}/ktexteditor_exporter ) diff --git a/kate/plugins/exporter/TODO b/kate/plugins/exporter/TODO new file mode 100644 index 0000000..d8ca015 --- /dev/null +++ b/kate/plugins/exporter/TODO @@ -0,0 +1,13 @@ +1) add more exporters +- LaTeX +- Bash color codes +- ??? + +2) add dialog for export action +- select exporter +- copy to clipboard +- save to file + +3) make it possible to run this from the outside + +4) optionally add linenumbers \ No newline at end of file diff --git a/kate/plugins/exporter/abstractexporter.h b/kate/plugins/exporter/abstractexporter.h new file mode 100644 index 0000000..0c8f72e --- /dev/null +++ b/kate/plugins/exporter/abstractexporter.h @@ -0,0 +1,80 @@ +/** + * This file is part of the KDE libraries + * Copyright (C) 2009 Milian Wolff <mail@...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef ABSTRACTEXPORTER_H +#define ABSTRACTEXPORTER_H + +#include <QtCore/QTextStream> + +#include <ktexteditor/range.h> +#include <ktexteditor/attribute.h> +#include <ktexteditor/document.h> +#include <ktexteditor/view.h> +#include <ktexteditor/configinterface.h> +#include <ktexteditor/highlightinterface.h> + +class AbstractExporter +{ + public: + /// If \p m_encapsulate is set, you should add some kind of header in the ctor + /// to \p m_output. + AbstractExporter(KTextEditor::View* view, + QTextStream &output, const bool encapsulate = false) + : m_view(view), m_output(output), m_encapsulate(encapsulate), + m_defaultAttribute(0) + { + QColor defaultBackground; + if ( KTextEditor::ConfigInterface* ciface = qobject_cast< KTextEditor::ConfigInterface* >(m_view) ) { + QVariant variant = ciface->configValue("background-color"); + if ( variant.canConvert<QColor>() ) { + defaultBackground = variant.value<QColor>(); + } + } + if ( KTextEditor::HighlightInterface* hiface = qobject_cast< KTextEditor::HighlightInterface* >(m_view->document()) ) { + m_defaultAttribute = hiface->defaultStyle(KTextEditor::HighlightInterface::dsNormal); + m_defaultAttribute->setBackground(QBrush(defaultBackground)); + } + } + + /// Gets called after everything got exported. + /// Hence, if \p m_encapsulate is set, you should probably add some kind of footer here. + virtual ~AbstractExporter() + {} + + /// Begin a new line. + virtual void openLine() = 0; + + /// Finish the current line. + virtual void closeLine(const bool lastLine) = 0; + + /// Export \p text with given text attribute \p attrib. + /// NOTE: Check \p attrib, it might be null for KTextEditors that do not implement the + /// HighlightInterface. + virtual void exportText(const QString& text, const KTextEditor::Attribute::Ptr& attrib) = 0; + + protected: + KTextEditor::View* m_view; + QTextStream &m_output; + bool m_encapsulate; + KTextEditor::Attribute::Ptr m_defaultAttribute; +}; + +#endif // ABSTRACTEXPORTER_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/plugins/exporter/exporterplugin.cpp b/kate/plugins/exporter/exporterplugin.cpp new file mode 100644 index 0000000..39b4af0 --- /dev/null +++ b/kate/plugins/exporter/exporterplugin.cpp @@ -0,0 +1,51 @@ +/** + * This file is part of the KDE libraries + * Copyright (C) 2009 Milian Wolff <mail@...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "exporterplugin.h" + +#include <kpluginloader.h> + +#include <ktexteditor/view.h> + +#include "exporterpluginview.h" + +K_PLUGIN_FACTORY_DEFINITION(ExporterPluginFactory, + registerPlugin<ExporterPlugin>("ktexteditor_exporter"); + ) +K_EXPORT_PLUGIN(ExporterPluginFactory("ktexteditor_exporter", "ktexteditor_plugins")) + +ExporterPlugin::ExporterPlugin(QObject *parent, const QVariantList &args) + : KTextEditor::Plugin(parent) +{ + Q_UNUSED(args); +} + +ExporterPlugin::~ExporterPlugin() +{ +} + +void ExporterPlugin::addView(KTextEditor::View *view) +{ + // no need to keep track of, QObject inheritance will take care of deletion + new ExporterPluginView(view); +} + +#include "exporterplugin.moc" + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/plugins/exporter/exporterplugin.h b/kate/plugins/exporter/exporterplugin.h new file mode 100644 index 0000000..fd814ac --- /dev/null +++ b/kate/plugins/exporter/exporterplugin.h @@ -0,0 +1,51 @@ +/** + * This file is part of the KDE libraries + * Copyright (C) 2009 Milian Wolff <mail@...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef EXPORTERPLUGIN_H +#define EXPORTERPLUGIN_H + +#include <ktexteditor/plugin.h> + +#include <kpluginfactory.h> + +#include <QtCore/QVariantList> + +namespace KTextEditor { +class View; +} + +class ExporterPluginView; + +class ExporterPlugin + : public KTextEditor::Plugin +{ + Q_OBJECT + + public: + explicit ExporterPlugin(QObject *parent = 0, const QVariantList &args = QVariantList()); + virtual ~ExporterPlugin(); + + virtual void addView (KTextEditor::View *view); +}; + +K_PLUGIN_FACTORY_DECLARATION(ExporterPluginFactory) + +#endif // EXPORTERPLUGIN_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/plugins/exporter/exporterpluginview.cpp b/kate/plugins/exporter/exporterpluginview.cpp new file mode 100644 index 0000000..e990913 --- /dev/null +++ b/kate/plugins/exporter/exporterpluginview.cpp @@ -0,0 +1,207 @@ +/** + * This file is part of the KDE libraries + * Copyright (C) 2009 Milian Wolff <mail@...> + * Copyright (C) 2002 John Firebaugh <jfirebaugh@...> + * Copyright (C) 2001 Christoph Cullmann <cullmann@...> + * Copyright (C) 2001 Joseph Wenninger <jowenn@...> + * Copyright (C) 1999 Jochen Wilhelmy <digisnap@...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "exporterpluginview.h" + +#include "exporterplugin.h" +#include "abstractexporter.h" +#include "htmlexporter.h" + +#include <ktexteditor/document.h> +#include <ktexteditor/view.h> +#include <ktexteditor/highlightinterface.h> + +#include <kactioncollection.h> +#include <kaction.h> +#include <kfiledialog.h> +#include <ktemporaryfile.h> +#include <ksavefile.h> +#include <kio/netaccess.h> + +#include <QtCore/QMimeData> +#include <QtGui/QApplication> +#include <QtGui/QClipboard> +#include <QtCore/QTextCodec> + +#include <kdebug.h> + +ExporterPluginView::ExporterPluginView(KTextEditor::View* view) + : QObject(view), KXMLGUIClient(view), m_view(view) +{ + setComponentData( ExporterPluginFactory::componentData() ); + setXMLFile("ktexteditor_exporterui.rc"); + + m_copyAction = actionCollection()->addAction("edit_copy_html", this, SLOT(exportToClipboard())); + m_copyAction->setIcon(KIcon("edit-copy")); + m_copyAction->setText(i18n("Copy as &HTML")); + m_copyAction->setWhatsThis(i18n("Use this command to copy the currently selected text as HTML to the system clipboard.")); + m_copyAction->setEnabled(m_view->selection()); + + m_fileExportAction = actionCollection()->addAction("file_export_html", this, SLOT(exportToFile())); + m_fileExportAction->setText(i18n("E&xport as HTML...")); + m_fileExportAction->setWhatsThis(i18n("This command allows you to export the current document" + " with all highlighting information into a HTML document.")); + + connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), + this, SLOT(updateSelectionAction(KTextEditor::View*))); +} + +ExporterPluginView::~ExporterPluginView() +{ +} + +void ExporterPluginView::updateSelectionAction(KTextEditor::View* view) +{ + Q_ASSERT(view == m_view); + m_copyAction->setEnabled(m_view->selection()); +} + +void ExporterPluginView::exportToClipboard() +{ + if (!m_view->selection()) { + return; + } + + QMimeData *data = new QMimeData(); + data->setText(m_view->selectionText()); + + QString s; + QTextStream output( &s, QIODevice::WriteOnly ); + exportData(true, output); + + data->setHtml(s); + + QApplication::clipboard()->setMimeData(data); +} + +void ExporterPluginView::exportToFile() +{ + KUrl url = KFileDialog::getSaveUrl(m_view->document()->documentName(), "text/html", + m_view, i18n("Export File as HTML")); + + if ( url.isEmpty() ) { + return; + } + + QString filename; + + if ( url.isLocalFile() ) { + filename = url.toLocalFile(); + } else { + ///TODO: cleanup! don't let the temp files lay around + KTemporaryFile tmp; // ### only used for network export + tmp.setAutoRemove(false); + tmp.open(); + filename = tmp.fileName(); + } + + KSaveFile savefile(filename); + if (savefile.open()) { + QTextStream outputStream ( &savefile ); + + exportData(false, outputStream); + + savefile.finalize(); //check error? + } +// else +// {/*ERROR*/} + + if ( !url.isLocalFile() ) { + KIO::NetAccess::upload( filename, url, 0 ); + } +} + +void ExporterPluginView::exportData(const bool useSelection, QTextStream &output) +{ + const KTextEditor::Range range = useSelection ? m_view->selectionRange() : m_view->document()->documentRange(); + const bool blockwise = useSelection ? m_view->blockSelection() : false; + + if ( (blockwise || range.onSingleLine()) && (range.start().column() > range.end().column() ) ) { + return; + } + + //outputStream.setEncoding(QTextStream::UnicodeUTF8); + output.setCodec(QTextCodec::codecForName("UTF-8")); + + ///TODO: add more exporters + AbstractExporter* exporter; + + exporter = new HTMLExporter(m_view, output, !useSelection); + + KTextEditor::HighlightInterface* hiface = qobject_cast<KTextEditor::HighlightInterface*>(m_view->document()); + + const KTextEditor::Attribute::Ptr noAttrib(0); + + for (int i = range.start().line(); (i <= range.end().line()) && (i < m_view->document()->lines()); ++i) + { + const QString &line = m_view->document()->line(i); + + QList<KTextEditor::HighlightInterface::AttributeBlock> attribs; + if ( hiface ) { + attribs = hiface->lineAttributes(i); + } + + int lineStart = 0; + int remainingChars = line.length(); + if ( blockwise || range.onSingleLine() ) { + lineStart = range.start().column(); + remainingChars = range.columnWidth(); + } else if ( i == range.start().line() ) { + lineStart = range.start().column(); + } else if ( i == range.end().line() ) { + remainingChars = range.end().column(); + } + + int handledUntil = lineStart; + + foreach ( const KTextEditor::HighlightInterface::AttributeBlock& block, attribs ) { + // honor (block-) selections + if ( block.start + block.length <= lineStart ) { + continue; + } else if ( block.start >= lineStart + remainingChars ) { + break; + } + int start = qMax(block.start, lineStart); + if ( start > handledUntil ) { + exporter->exportText( line.mid( handledUntil, start - handledUntil ), noAttrib ); + } + int length = qMin(block.length, remainingChars); + exporter->exportText( line.mid( start, length ), block.attribute); + handledUntil = start + length; + } + + if ( handledUntil < lineStart + remainingChars ) { + exporter->exportText( line.mid( handledUntil, remainingChars ), noAttrib ); + } + + exporter->closeLine(i == range.end().line()); + } + + delete exporter; + + output.flush(); +} + +#include "exporterpluginview.moc" + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/plugins/exporter/exporterpluginview.h b/kate/plugins/exporter/exporterpluginview.h new file mode 100644 index 0000000..9e3e52a --- /dev/null +++ b/kate/plugins/exporter/exporterpluginview.h @@ -0,0 +1,58 @@ +/** + * This file is part of the KDE libraries + * Copyright (C) 2009 Milian Wolff <mail@...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef EXPORTERPLUGINVIEW_H +#define EXPORTERPLUGINVIEW_H + +#include <QtCore/QObject> +#include <kxmlguiclient.h> + +#include <ktexteditor/range.h> + +namespace KTextEditor { +class View; +} + +class ExporterPluginView : public QObject, public KXMLGUIClient +{ + Q_OBJECT + + public: + ExporterPluginView(KTextEditor::View* view = 0); + ~ExporterPluginView(); + + private: + ///TODO: maybe make this scriptable for additional exporters? + void exportData(const bool useSelction, QTextStream& output); + + private slots: + void exportToClipboard(); + void exportToFile(); + + void updateSelectionAction(KTextEditor::View *view); + + private: + KTextEditor::View* m_view; + QAction* m_copyAction; + QAction* m_fileExportAction; +}; + +#endif // EXPORTERPLUGINVIEW_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/plugins/exporter/htmlexporter.cpp b/kate/plugins/exporter/htmlexporter.cpp new file mode 100644 index 0000000..4dce9b1 --- /dev/null +++ b/kate/plugins/exporter/htmlexporter.cpp @@ -0,0 +1,119 @@ +/** + * This file is part of the KDE libraries + * Copyright (C) 2009 Milian Wolff <mail@...> + * Copyright (C) 2002 John Firebaugh <jfirebaugh@...> + * Copyright (C) 2001 Christoph Cullmann <cullmann@...> + * Copyright (C) 2001 Joseph Wenninger <jowenn@...> + * Copyright (C) 1999 Jochen Wilhelmy <digisnap@...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "htmlexporter.h" + +#include <ktexteditor/document.h> + +#include <QtGui/QTextDocument> + +HTMLExporter::HTMLExporter(KTextEditor::View* view, QTextStream& output, const bool encapsulate) + : AbstractExporter(view, output, encapsulate) +{ + if ( m_encapsulate ) { + // let's write the HTML header : + m_output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; + m_output << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl; + m_output << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl; + m_output << "<head>" << endl; + m_output << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl; + m_output << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl; + // for the title, we write the name of the file (/usr/local/emmanuel/myfile.cpp -> myfile.cpp) + m_output << "<title>" << view->document()->documentName() << "</title>" << endl; + m_output << "</head>" << endl; + m_output << "<body>" << endl; + } + + if ( !m_defaultAttribute ) { + m_output << "<pre>" << endl; + } else { + m_output << QString("<pre style='%1%2%3%4'>") + .arg(m_defaultAttribute->fontBold() ? "font-weight:bold;" : "") + .arg(m_defaultAttribute->fontItalic() ? "text-style:italic;" : "") + .arg("color:" + m_defaultAttribute->foreground().color().name() + ";") + .arg("background-color:" + m_defaultAttribute->background().color().name() + ";") + << endl; + } +} + +HTMLExporter::~HTMLExporter() +{ + m_output << "</pre>" << endl; + + if ( m_encapsulate ) { + m_output << "</body>" << endl; + m_output << "</html>" << endl; + } +} + +void HTMLExporter::openLine() +{ +} + +void HTMLExporter::closeLine(const bool lastLine) +{ + if ( !lastLine ) { + //we are inside a <pre>, so a \n is a new line + m_output << "\n"; + } +} + +void HTMLExporter::exportText(const QString& text, const KTextEditor::Attribute::Ptr& attrib) +{ + if ( !attrib || !attrib->hasAnyProperty() || attrib == m_defaultAttribute ) { + m_output << Qt::escape(text); + return; + } + + if ( attrib->fontBold() ) { + m_output << "<b>"; + } + if ( attrib->fontItalic() ) { + m_output << "<i>"; + } + + bool writeForeground = attrib->hasProperty(QTextCharFormat::ForegroundBrush) + && (!m_defaultAttribute || attrib->foreground().color() != m_defaultAttribute->foreground().color()); + bool writeBackground = attrib->hasProperty(QTextCharFormat::BackgroundBrush) + && (!m_defaultAttribute || attrib->background().color() != m_defaultAttribute->background().color()); + + if ( writeForeground || writeBackground ) { + m_output << QString("<span style='%1%2'>") + .arg(writeForeground ? "color:" + attrib->foreground().color().name() + ";" : "") + .arg(writeBackground ? "background:" + attrib->background().color().name() + ";" : ""); + } + + m_output << Qt::escape(text); + + if ( writeBackground || writeForeground ) { + m_output << "</span>"; + } + if ( attrib->fontItalic() ) { + m_output << "</i>"; + } + if ( attrib->fontBold() ) { + m_output << "</b>"; + } +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/plugins/exporter/htmlexporter.h b/kate/plugins/exporter/htmlexporter.h new file mode 100644 index 0000000..1d47acf --- /dev/null +++ b/kate/plugins/exporter/htmlexporter.h @@ -0,0 +1,39 @@ +/** + * This file is part of the KDE libraries + * Copyright (C) 2009 Milian Wolff <mail@...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef HTMLEXPORTER_H +#define HTMLEXPORTER_H + +#include "abstractexporter.h" + +/// TODO: add abstract interface for future exporters +class HTMLExporter : public AbstractExporter +{ + public: + HTMLExporter(KTextEditor::View* view, QTextStream& output, const bool withHeaderFooter = false); + virtual ~HTMLExporter(); + + virtual void openLine(); + virtual void closeLine(const bool lastLine); + virtual void exportText(const QString& text, const KTextEditor::Attribute::Ptr& attrib); +}; + +#endif // HTMLEXPORTER_H + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/plugins/exporter/ktexteditor_exporter.desktop b/kate/plugins/exporter/ktexteditor_exporter.desktop new file mode 100644 index 0000000..43b9ae5 --- /dev/null +++ b/kate/plugins/exporter/ktexteditor_exporter.desktop @@ -0,0 +1,21 @@ +[Desktop Entry] +X-KDE-Library=ktexteditor_exporter +X-KDE-PluginKeyword=ktexteditor_exporter +X-KDE-PluginInfo-Author=Milian Wolff +X-KDE-PluginInfo-Email=mail@... +X-KDE-PluginInfo-Name=ktexteditorexporter +X-KDE-PluginInfo-Version=0.1 +X-KDE-PluginInfo-Website=http://kate.kde.org +X-KDE-PluginInfo-Category=Editor +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=false +X-KDE-ParentApp=kate +X-KDE-Version=4.0 +X-KDE-ServiceTypes=KTextEditor/Plugin +Type=Service +Icon=ktexteditorexporter +Name=Exporter +Name[x-test]=xxExporterxx +Comment=Export highlighted document to HTML +Comment[x-test]=xxExport highlighted document to HTMLxx diff --git a/kate/plugins/exporter/ktexteditor_exporterui.rc b/kate/plugins/exporter/ktexteditor_exporterui.rc new file mode 100644 index 0000000..80c309d --- /dev/null +++ b/kate/plugins/exporter/ktexteditor_exporterui.rc @@ -0,0 +1,14 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<gui name="ktexteditor_exporter" library="ktexteditor_exporter" version="1"> + +<MenuBar> + <Menu name="file" noMerge="1"><text>&File</text> + <Action name="file_export_html" group="print_merge"/> + </Menu> + + <Menu name="edit" noMerge="1"><text>&Edit</text> + <Action name="edit_copy_html" group="edit_paste_merge" /> + </Menu> +</MenuBar> + +</gui> diff --git a/kate/render/katerenderer.cpp b/kate/render/katerenderer.cpp index d79d23d..57db571 100644 --- a/kate/render/katerenderer.cpp +++ b/kate/render/katerenderer.cpp @@ -40,6 +40,8 @@ #include <QtCore/QStack> #include <QtGui/QBrush> +#include <ktexteditor/highlightinterface.h> + static const QChar tabChar('\t'); static const QChar spaceChar(' '); @@ -325,7 +327,7 @@ QList<QTextLayout::FormatRange> KateRenderer::decorationsForLine( const KateText backgroundAttribute = KTextEditor::Attribute::Ptr(new KTextEditor::Attribute()); backgroundAttribute->setBackground(config()->selectionColor()); - backgroundAttribute->setForeground(attribute(KateExtendedAttribute::dsNormal)->selectedForeground().color()); + backgroundAttribute->setForeground(attribute(KTextEditor::HighlightInterface::dsNormal)->selectedForeground().color()); // Create a range for the current selection if (completionHighlight && completionSelected) @@ -495,7 +497,7 @@ void KateRenderer::paintTextLine(QPainter& paint, KateLineLayoutPtr range, int x // We may have changed the pen, be absolutely sure it gets set back to // normal foreground color before drawing text for text that does not // set the pen color - paint.setPen(attribute(KateExtendedAttribute::dsNormal)->foreground().color()); + paint.setPen(attribute(KTextEditor::HighlightInterface::dsNormal)->foreground().color()); // Draw the text :) if (m_dynamicRegion.boundingRange().isValid() || (m_view->selection() && showSelections() && m_view->selectionRange().overlapsLine(range->line()))) { // FIXME toVector() may be a performance issue @@ -672,7 +674,7 @@ void KateRenderer::paintTextLine(QPainter& paint, KateLineLayoutPtr range, int x // still no color found, fall back to default style if (!c.isValid()) - c = attribute(KateExtendedAttribute::dsNormal)->foreground().color(); + c = attribute(KTextEditor::HighlightInterface::dsNormal)->foreground().color(); } // make it possible to see the selected character in the vi input mode's normal/visual mode diff --git a/kate/script/katescriptdocument.cpp b/kate/script/katescriptdocument.cpp index cd89ce7..950aed4 100644 --- a/kate/script/katescriptdocument.cpp +++ b/kate/script/katescriptdocument.cpp @@ -26,6 +26,8 @@ #include "katehighlight.h" #include "katescript.h" +#include <ktexteditor/highlightinterface.h> + #include <QtScript/QScriptEngine> KateScriptDocument::KateScriptDocument(QObject *parent) @@ -71,7 +73,7 @@ bool KateScriptDocument::isCode(const KTextEditor::Cursor& cursor) bool KateScriptDocument::isComment(int line, int column) { const int defaultStyle = defStyleNum(line, column); - return defaultStyle == KateExtendedAttribute::dsComment; + return defaultStyle == KTextEditor::HighlightInterface::dsComment; } bool KateScriptDocument::isComment(const KTextEditor::Cursor& cursor) @@ -82,7 +84,7 @@ bool KateScriptDocument::isComment(const KTextEditor::Cursor& cursor) bool KateScriptDocument::isString(int line, int column) { const int defaultStyle = defStyleNum(line, column); - return defaultStyle == KateExtendedAttribute::dsString; + return defaultStyle == KTextEditor::HighlightInterface::dsString; } bool KateScriptDocument::isString(const KTextEditor::Cursor& cursor) @@ -93,7 +95,7 @@ bool KateScriptDocument::isString(const KTextEditor::Cursor& cursor) bool KateScriptDocument::isRegionMarker(int line, int column) { const int defaultStyle = defStyleNum(line, column); - return defaultStyle == KateExtendedAttribute::dsRegionMarker; + return defaultStyle == KTextEditor::HighlightInterface::dsRegionMarker; } bool KateScriptDocument::isRegionMarker(const KTextEditor::Cursor& cursor) @@ -104,7 +106,7 @@ bool KateScriptDocument::isRegionMarker(const KTextEditor::Cursor& cursor) bool KateScriptDocument::isChar(int line, int column) { const int defaultStyle = defStyleNum(line, column); - return defaultStyle == KateExtendedAttribute::dsChar; + return defaultStyle == KTextEditor::HighlightInterface::dsChar; } bool KateScriptDocument::isChar(const KTextEditor::Cursor& cursor) @@ -115,7 +117,7 @@ bool KateScriptDocument::isChar(const KTextEditor::Cursor& cursor) bool KateScriptDocument::isOthers(int line, int column) { const int defaultStyle = defStyleNum(line, column); - return defaultStyle == KateExtendedAttribute::dsOthers; + return defaultStyle == KTextEditor::HighlightInterface::dsOthers; } bool KateScriptDocument::isOthers(const KTextEditor::Cursor& cursor) @@ -631,11 +633,11 @@ QString KateScriptDocument::variable(const QString &s) bool KateScriptDocument::_isCode(int defaultStyle) { - return (defaultStyle != KateExtendedAttribute::dsComment - && defaultStyle != KateExtendedAttribute::dsString - && defaultStyle != KateExtendedAttribute::dsRegionMarker - && defaultStyle != KateExtendedAttribute::dsChar - && defaultStyle != KateExtendedAttribute::dsOthers); + return (defaultStyle != KTextEditor::HighlightInterface::dsComment + && defaultStyle != KTextEditor::HighlightInterface::dsString + && defaultStyle != KTextEditor::HighlightInterface::dsRegionMarker + && defaultStyle != KTextEditor::HighlightInterface::dsChar + && defaultStyle != KTextEditor::HighlightInterface::dsOthers); } // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/syntax/kateextendedattribute.cpp b/kate/syntax/kateextendedattribute.cpp index 6049858..463dd78 100644 --- a/kate/syntax/kateextendedattribute.cpp +++ b/kate/syntax/kateextendedattribute.cpp @@ -22,6 +22,8 @@ #include "kateextendedattribute.h" +#include <ktexteditor/highlightinterface.h> + KateExtendedAttribute::KateExtendedAttribute(const QString& name, int defaultStyleIndex) { setName(name); @@ -31,22 +33,22 @@ KateExtendedAttribute::KateExtendedAttribute(const QString& name, int defaultSty int KateExtendedAttribute::indexForStyleName( const QString & name ) { - if (name=="dsNormal") return KateExtendedAttribute::dsNormal; - else if (name=="dsKeyword") return KateExtendedAttribute::dsKeyword; - else if (name=="dsDataType") return KateExtendedAttribute::dsDataType; - else if (name=="dsDecVal") return KateExtendedAttribute::dsDecVal; - else if (name=="dsBaseN") return KateExtendedAttribute::dsBaseN; - else if (name=="dsFloat") return KateExtendedAttribute::dsFloat; - else if (name=="dsChar") return KateExtendedAttribute::dsChar; - else if (name=="dsString") return KateExtendedAttribute::dsString; - else if (name=="dsComment") return KateExtendedAttribute::dsComment; - else if (name=="dsOthers") return KateExtendedAttribute::dsOthers; - else if (name=="dsAlert") return KateExtendedAttribute::dsAlert; - else if (name=="dsFunction") return KateExtendedAttribute::dsFunction; - else if (name=="dsRegionMarker") return KateExtendedAttribute::dsRegionMarker; - else if (name=="dsError") return KateExtendedAttribute::dsError; + if (name=="dsNormal") return KTextEditor::HighlightInterface::dsNormal; + else if (name=="dsKeyword") return KTextEditor::HighlightInterface::dsKeyword; + else if (name=="dsDataType") return KTextEditor::HighlightInterface::dsDataType; + else if (name=="dsDecVal") return KTextEditor::HighlightInterface::dsDecVal; + else if (name=="dsBaseN") return KTextEditor::HighlightInterface::dsBaseN; + else if (name=="dsFloat") return KTextEditor::HighlightInterface::dsFloat; + else if (name=="dsChar") return KTextEditor::HighlightInterface::dsChar; + else if (name=="dsString") return KTextEditor::HighlightInterface::dsString; + else if (name=="dsComment") return KTextEditor::HighlightInterface::dsComment; + else if (name=="dsOthers") return KTextEditor::HighlightInterface::dsOthers; + else if (name=="dsAlert") return KTextEditor::HighlightInterface::dsAlert; + else if (name=="dsFunction") return KTextEditor::HighlightInterface::dsFunction; + else if (name=="dsRegionMarker") return KTextEditor::HighlightInterface::dsRegionMarker; + else if (name=="dsError") return KTextEditor::HighlightInterface::dsError; - return KateExtendedAttribute::dsNormal; + return KTextEditor::HighlightInterface::dsNormal; } QString KateExtendedAttribute::name( ) const diff --git a/kate/syntax/kateextendedattribute.h b/kate/syntax/kateextendedattribute.h index 9c0d0e1..1c4d920 100644 --- a/kate/syntax/kateextendedattribute.h +++ b/kate/syntax/kateextendedattribute.h @@ -39,23 +39,6 @@ class KateExtendedAttribute : public KTextEditor::Attribute explicit KateExtendedAttribute(const QString& name, int defaultStyleIndex = -1); - enum DefaultStyle { - dsNormal, - dsKeyword, - dsDataType, - dsDecVal, - dsBaseN, - dsFloat, - dsChar, - dsString, - dsComment, - dsOthers, - dsAlert, - dsFunction, - dsRegionMarker, - dsError - }; - enum InternalProperties { AttributeName = AttributeInternalProperty, AttributeDefaultStyleIndex, diff --git a/kate/syntax/katehighlight.cpp b/kate/syntax/katehighlight.cpp index 9517d3e..660e3b4 100644 --- a/kate/syntax/katehighlight.cpp +++ b/kate/syntax/katehighlight.cpp @@ -46,6 +46,8 @@ #include <kmessagebox.h> #include <kapplication.h> +#include <ktexteditor/highlightinterface.h> + #include <QtCore/QSet> #include <QtGui/QAction> #include <QtGui/QApplication> @@ -256,7 +258,7 @@ void KateHighlighting::doHighlight ( KateTextLine *prevLine, // no hl set, nothing to do more than the above cleaning ;) if (noHl) { - textLine->addAttribute (0, textLine->length(), KateExtendedAttribute::dsNormal); + textLine->addAttribute (0, textLine->length(), KTextEditor::HighlightInterface::dsNormal); return; } @@ -494,7 +496,7 @@ void KateHighlighting::doHighlight ( KateTextLine *prevLine, //set the dsNormal attribute if we haven't found anything else if(textLine->attributesList().empty()) { - textLine->addAttribute (0, textLine->length(), KateExtendedAttribute::dsNormal); + textLine->addAttribute (0, textLine->length(), KTextEditor::HighlightInterface::dsNormal); } } @@ -686,7 +688,7 @@ void KateHighlighting::createKateExtendedAttribute(QList<KateExtendedAttribute:: // If no highlighting is selected we need only one default. if (noHl) { - list.append(KateExtendedAttribute::Ptr(new KateExtendedAttribute(i18n("Normal Text"), KateExtendedAttribute::dsNormal))); + list.append(KateExtendedAttribute::Ptr(new KateExtendedAttribute(i18n("Normal Text"), KTextEditor::HighlightInterface::dsNormal))); return; } @@ -1409,6 +1411,7 @@ void KateHighlighting::makeContextList() return; embeddedHls.clear(); + embeddedModes.clear(); unresolvedContextReferences.clear(); RegionList.clear(); ContextNameList.clear(); @@ -1497,6 +1500,9 @@ void KateHighlighting::makeContextList() // belongs to handleKateHlIncludeRules(); + embeddedModes = embeddedHls.keys(); + embeddedModes.removeOne(iName); + embeddedHls.clear(); //save some memory. unresolvedContextReferences.clear(); //save some memory RegionList.clear(); // I think you get the idea ;) @@ -1942,6 +1948,11 @@ QList<KTextEditor::Attribute::Ptr> KateHighlighting::attributes (const QString & return array; } +QStringList KateHighlighting::getEmbeddedModes() const +{ + return embeddedModes; +} + //END // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/syntax/katehighlight.h b/kate/syntax/katehighlight.h index ab37b77..433622d 100644 --- a/kate/syntax/katehighlight.h +++ b/kate/syntax/katehighlight.h @@ -245,6 +245,11 @@ class KateHighlighting const QHash<QChar, QString>& getReverseCharacterEncodings( int attrib ) const; int getEncodedCharactersInsertionPolicy( int attrib ) const; + /** + * Returns a list of names of embedded modes. + */ + QStringList getEmbeddedModes() const; + private: /** * 'encoding' must not contain new line characters, i.e. '\n' or '\r'! @@ -292,7 +297,10 @@ class KateHighlighting QMap< QPair<KateHlContext *, QString>, short> dynamicCtxs; // make them pointers perhaps + // NOTE: gets cleaned once makeContextList() finishes KateEmbeddedHlInfos embeddedHls; + // valid once makeContextList() finishes + QStringList embeddedModes; KateHlUnresolvedCtxRefs unresolvedContextReferences; QStringList RegionList; QStringList ContextNameList; diff --git a/kate/syntax/katesyntaxmanager.cpp b/kate/syntax/katesyntaxmanager.cpp index d8200bc..ad7d8e3 100644 --- a/kate/syntax/katesyntaxmanager.cpp +++ b/kate/syntax/katesyntaxmanager.cpp @@ -53,6 +53,8 @@ #include <QtCore/QTextStream> //END +using namespace KTextEditor; + //BEGIN KateHlManager KateHlManager::KateHlManager() : QObject() @@ -170,86 +172,111 @@ QString KateHlManager::defaultStyleName(int n, bool translateNames) return translateNames ? translatedNames[n] : names[n]; } -void KateHlManager::getDefaults(const QString &schema, KateAttributeList &list) +Attribute::Ptr KateHlManager::getDefaultAttribute(const HighlightInterface::DefaultStyle ds) const { + // TODO: Is it too inefficient to always create this for every attrib? KColorScheme scheme(QPalette::Active, KColorScheme::View); KColorScheme schemeSelected(QPalette::Active, KColorScheme::Selection); - KTextEditor::Attribute::Ptr normal(new KTextEditor::Attribute()); - normal->setForeground( scheme.foreground().color() ); - normal->setSelectedForeground( schemeSelected.foreground().color() ); - list.append(normal); - - KTextEditor::Attribute::Ptr keyword(new KTextEditor::Attribute()); - keyword->setForeground( scheme.foreground().color() ); - keyword->setSelectedForeground( schemeSelected.foreground().color() ); - keyword->setFontBold(true); - list.append(keyword); - - KTextEditor::Attribute::Ptr dataType(new KTextEditor::Attribute()); - dataType->setForeground( scheme.foreground(KColorScheme::LinkText).color() ); - dataType->setSelectedForeground( schemeSelected.foreground(KColorScheme::LinkText).color() ); - list.append(dataType); - - KTextEditor::Attribute::Ptr decimal(new KTextEditor::Attribute()); - decimal->setForeground( scheme.foreground(KColorScheme::NeutralText).color() ); - decimal->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() ); - list.append(decimal); - - KTextEditor::Attribute::Ptr basen(new KTextEditor::Attribute()); - basen->setForeground( scheme.foreground(KColorScheme::NeutralText).color() ); - basen->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() ); - list.append(basen); - - KTextEditor::Attribute::Ptr floatAttribute(new KTextEditor::Attribute()); - floatAttribute->setForeground( scheme.foreground(KColorScheme::NeutralText).color() ); - floatAttribute->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() ); - list.append(floatAttribute); - - KTextEditor::Attribute::Ptr charAttribute(new KTextEditor::Attribute()); - charAttribute->setForeground( scheme.foreground(KColorScheme::ActiveText).color() ); - charAttribute->setSelectedForeground( schemeSelected.foreground(KColorScheme::ActiveText).color() ); - list.append(charAttribute); - - KTextEditor::Attribute::Ptr string(new KTextEditor::Attribute()); - string->setForeground( scheme.foreground(KColorScheme::NegativeText).color() ); - string->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() ); - list.append(string); - - KTextEditor::Attribute::Ptr comment(new KTextEditor::Attribute()); - comment->setForeground( scheme.foreground(KColorScheme::InactiveText).color() ); - comment->setSelectedForeground( schemeSelected.foreground(KColorScheme::InactiveText).color() ); - comment->setFontItalic(true); - list.append(comment); - - KTextEditor::Attribute::Ptr others(new KTextEditor::Attribute()); - others->setForeground( scheme.foreground(KColorScheme::PositiveText).color() ); - others->setSelectedForeground( schemeSelected.foreground(KColorScheme::PositiveText).color() ); - list.append(others); - - KTextEditor::Attribute::Ptr alert(new KTextEditor::Attribute()); - alert->setForeground( scheme.foreground(KColorScheme::NegativeText).color() ); - alert->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() ); - alert->setFontBold(true); - alert->setBackground( scheme.background(KColorScheme::NegativeBackground).color() ); - list.append(alert); - - KTextEditor::Attribute::Ptr functionAttribute(new KTextEditor::Attribute()); - functionAttribute->setForeground( scheme.foreground(KColorScheme::VisitedText).color() ); - functionAttribute->setSelectedForeground( schemeSelected.foreground(KColorScheme::VisitedText).color() ); - list.append(functionAttribute); - - KTextEditor::Attribute::Ptr regionmarker(new KTextEditor::Attribute()); - regionmarker->setForeground( scheme.foreground(KColorScheme::LinkText).color() ); - regionmarker->setSelectedForeground( schemeSelected.foreground(KColorScheme::LinkText).color() ); - regionmarker->setBackground( scheme.background(KColorScheme::LinkBackground).color() ); - list.append(regionmarker); - - KTextEditor::Attribute::Ptr error(new KTextEditor::Attribute()); - error->setForeground( scheme.foreground(KColorScheme::NegativeText) ); - error->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() ); - error->setFontUnderline(true); - list.append(error); + Attribute::Ptr attrib(new KTextEditor::Attribute()); + + switch ( ds ) { + case HighlightInterface::dsNormal: + attrib->setForeground( scheme.foreground().color() ); + attrib->setSelectedForeground( schemeSelected.foreground().color() ); + break; + case HighlightInterface::dsKeyword: + attrib->setForeground( scheme.foreground().color() ); + attrib->setSelectedForeground( schemeSelected.foreground().color() ); + attrib->setFontBold(true); + break; + case HighlightInterface::dsDataType: + attrib->setForeground( scheme.foreground(KColorScheme::LinkText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::LinkText).color() ); + break; + case HighlightInterface::dsDecVal: + attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() ); + break; + case HighlightInterface::dsBaseN: + attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() ); + break; + case HighlightInterface::dsFloat: + attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() ); + break; + case HighlightInterface::dsChar: + attrib->setForeground( scheme.foreground(KColorScheme::ActiveText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::ActiveText).color() ); + break; + case HighlightInterface::dsString: + attrib->setForeground( scheme.foreground(KColorScheme::NegativeText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() ); + break; + case HighlightInterface::dsComment: + attrib->setForeground( scheme.foreground(KColorScheme::InactiveText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::InactiveText).color() ); + attrib->setFontItalic(true); + break; + case HighlightInterface::dsOthers: + attrib->setForeground( scheme.foreground(KColorScheme::PositiveText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::PositiveText).color() ); + break; + case HighlightInterface::dsAlert: + attrib->setForeground( scheme.foreground(KColorScheme::NegativeText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() ); + attrib->setFontBold(true); + attrib->setBackground( scheme.background(KColorScheme::NegativeBackground).color() ); + break; + case HighlightInterface::dsFunction: + attrib->setForeground( scheme.foreground(KColorScheme::VisitedText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::VisitedText).color() ); + break; + case HighlightInterface::dsRegionMarker: + attrib->setForeground( scheme.foreground(KColorScheme::LinkText).color() ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::LinkText).color() ); + attrib->setBackground( scheme.background(KColorScheme::LinkBackground).color() ); + break; + case HighlightInterface::dsError: + attrib->setForeground( scheme.foreground(KColorScheme::NegativeText) ); + attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() ); + attrib->setFontUnderline(true); + break; + } + + return attrib; +} + +void KateHlManager::getDefaults(const QString &schema, KateAttributeList &list) +{ + list.append(getDefaultAttribute(HighlightInterface::dsNormal)); + + list.append(getDefaultAttribute(HighlightInterface::dsKeyword)); + + list.append(getDefaultAttribute(HighlightInterface::dsDataType)); + + list.append(getDefaultAttribute(HighlightInterface::dsDecVal)); + + list.append(getDefaultAttribute(HighlightInterface::dsBaseN)); + + list.append(getDefaultAttribute(HighlightInterface::dsFloat)); + + list.append(getDefaultAttribute(HighlightInterface::dsChar)); + + list.append(getDefaultAttribute(HighlightInterface::dsString)); + + list.append(getDefaultAttribute(HighlightInterface::dsComment)); + + list.append(getDefaultAttribute(HighlightInterface::dsOthers)); + + list.append(getDefaultAttribute(HighlightInterface::dsAlert)); + + list.append(getDefaultAttribute(HighlightInterface::dsFunction)); + + list.append(getDefaultAttribute(HighlightInterface::dsRegionMarker)); + + list.append(getDefaultAttribute(HighlightInterface::dsError)); KConfigGroup config(KateHlManager::self()->self()->getKConfig(), "Default Item Styles - Schema " + schema); @@ -365,6 +392,19 @@ QString KateHlManager::identifierForName(const QString& name) return QString(); } +QString KateHlManager::nameForIdentifier(const QString& identifier) +{ + for ( QHash<QString, KateHighlighting*>::iterator it = hlDict.begin(); + it != hlDict.end(); ++it ) + { + if ( (*it)->getIdentifier() == identifier ) { + return it.key(); + } + } + + return QString(); +} + bool KateHlManager::resetDynamicCtxs() { if (forceNoDCReset) diff --git a/kate/syntax/katesyntaxmanager.h b/kate/syntax/katesyntaxmanager.h index a3cb0ed..995b740 100644 --- a/kate/syntax/katesyntaxmanager.h +++ b/kate/syntax/katesyntaxmanager.h @@ -24,6 +24,8 @@ #include "katetextline.h" #include "kateextendedattribute.h" +#include <ktexteditor/highlightinterface.h> + #include <kconfig.h> #include <kactionmenu.h> @@ -61,11 +63,17 @@ class KateHlManager : public QObject int nameFind(const QString &name); QString identifierForName(const QString&); + /** + * Returns the mode name for a given identifier, as e.g. + * returned by KateHighlighting::hlKeyForAttrib(). + */ + QString nameForIdentifier(const QString&); // methodes to get the default style count + names static uint defaultStyles(); static QString defaultStyleName(int n, bool translateNames = false); + KTextEditor::Attribute::Ptr getDefaultAttribute(const KTextEditor::HighlightInterface::DefaultStyle ds) const; void getDefaults(const QString &schema, KateAttributeList &); void setDefaults(const QString &schema, KateAttributeList &); diff --git a/kate/utils/katehtmlexporter.cpp b/kate/utils/katehtmlexporter.cpp deleted file mode 100644 index 6d34c2d..0000000 --- a/kate/utils/katehtmlexporter.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2009 Bernhard Beschow <bbeschow at cs.tu-berlin.de> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "katehtmlexporter.h" -#include "katehtmlexporter.moc" - -#include "katerenderer.h" -#include "katedocument.h" -#include "kateglobal.h" -#include "katetextline.h" -#include "kateview.h" - -#include <kio/netaccess.h> - -#include <kapplication.h> -#include <klocale.h> -#include <kaction.h> -#include <kfiledialog.h> -#include <ktemporaryfile.h> -#include <ksavefile.h> -#include <kactioncollection.h> - -#include <QtGui/QClipboard> -#include <QtGui/QTextDocument> -#include <QtCore/QTextCodec> - -KateHTMLExporter::KateHTMLExporter( KateView *view ) - : QObject( view ) - , KXMLGUIClient( view ) - , m_view( view ) -{ - setComponentData(KateGlobal::self()->componentData()); - setXMLFile("katepart_htmlexporterui.rc"); - - KActionCollection *ac = actionCollection (); - - m_copyHTML = ac->addAction("edit_copy_html", this, SLOT(copyHTML())); - m_copyHTML->setIcon(KIcon("edit-copy")); - m_copyHTML->setText(i18n("Copy as &HTML")); - m_copyHTML->setWhatsThis(i18n("Use this command to copy the currently selected text as HTML to the system clipboard.")); - - m_exportHTML = ac->addAction("file_export_html", this, SLOT(exportAsHTML())); - m_exportHTML->setText(i18n("E&xport as HTML...")); - m_exportHTML->setWhatsThis(i18n("This command allows you to export the current document" - " with all highlighting information into a HTML document.")); - - connect(view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(slotUpdateActions())); - - slotUpdateActions(); -} - -KateHTMLExporter::~KateHTMLExporter() -{} - -void KateHTMLExporter::slotUpdateActions () -{ - m_copyHTML->setEnabled (m_view->selection()); -} - -void KateHTMLExporter::copyHTML() -{ - if (!m_view->selection()) - return; - - QMimeData *data = new QMimeData(); - data->setText(m_view->selectionText()); - data->setHtml(selectionAsHtml()); - QApplication::clipboard()->setMimeData(data); -} - -QString KateHTMLExporter::selectionAsHtml() -{ - KTextEditor::Range range = m_view->selectionRange(); - const bool blockwise = m_view->blockSelectionMode(); - - if (blockwise) - KateView::blockFix(range); - - return textAsHtml(range, blockwise); -} - -QString KateHTMLExporter::textAsHtml ( const KTextEditor::Range &range, bool blockwise) -{ - kDebug(13020) << "textAsHtml"; - - QString s; - QTextStream ts( &s, QIODevice::WriteOnly ); - ts.setCodec(QTextCodec::codecForName("UTF-8")); - - ts << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl; - ts << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl; - ts << "<head>" << endl; - ts << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl; - ts << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl; - ts << "</head>" << endl; - - ts << "<body>" << endl; - textAsHtmlStream(range, blockwise, ts); - - ts << "</body>" << endl; - ts << "</html>" << endl; - - kDebug(13020) << "html is: " << s; - - return s; -} - -void KateHTMLExporter::textAsHtmlStream ( const KTextEditor::Range& range, bool blockwise, QTextStream &ts) -{ - if ( (blockwise || range.onSingleLine()) && (range.start().column() > range.end().column() ) ) - return; - - if (range.onSingleLine()) - { - KateTextLine::Ptr textLine = document()->kateTextLine(range.start().line()); - if ( !textLine ) - return; - - ts << "<pre>" << endl; - - lineAsHTML(*textLine, range.start().column(), range.columnWidth(), ts); - } - else - { - ts << "<pre>" << endl; - - for (int i = range.start().line(); (i <= range.end().line()) && (i < document()->lines()); ++i) - { - KateTextLine::Ptr textLine = document()->kateTextLine(i); - - if ( !blockwise ) - { - if (i == range.start().line()) - lineAsHTML(*textLine, range.start().column(), textLine->length() - range.start().column(), ts); - else if (i == range.end().line()) - lineAsHTML(*textLine, 0, range.end().column(), ts); - else - lineAsHTML(*textLine, 0, textLine->length(), ts); - } - else - { - lineAsHTML(*textLine, range.start().column(), range.columnWidth(), ts); - } - - if ( i < range.end().line() ) - ts << "\n"; //we are inside a <pre>, so a \n is a new line - } - } - ts << "</pre>"; -} - -void KateHTMLExporter::lineAsHTML (const KateTextLine &line, const int startCol, const int length, QTextStream &outputStream) -{ - const QColor blackColor(Qt::black); - - // some variables : - bool previousCharacterWasBold = false; - bool previousCharacterWasItalic = false; - // when entering a new color, we'll close all the <b> & <i> tags, - // for HTML compliancy. that means right after that font tag, we'll - // need to reinitialize the <b> and <i> tags. - bool needToReinitializeTags = false; - QColor previousCharacterColor(blackColor); // default color of HTML characters is black - - - // for each character of the line : (curPos is the position in the line) - for (int curPos=startCol;curPos<(length+startCol);curPos++) - { - KTextEditor::Attribute::Ptr charAttributes = renderer()->attribute(line.attribute(curPos)); - - //ASSERT(charAttributes != NULL); - // let's give the color for that character : - if ( (charAttributes->foreground() != previousCharacterColor)) - { // the new character has a different color : - // if we were in a bold or italic section, close it - if (previousCharacterWasBold) - outputStream << "</b>"; - if (previousCharacterWasItalic) - outputStream << "</i>"; - - // close the previous font tag : - if(previousCharacterColor != blackColor) - outputStream << "</span>"; - // let's read that color : - int red, green, blue; - // getting the red, green, blue values of the color : - charAttributes->foreground().color().getRgb(&red, &green, &blue); - if(!(red == 0 && green == 0 && blue == 0)) { - outputStream << "<span style='color: #" - << ( (red < 0x10)?"0":"") // need to put 0f, NOT f for instance. don't touch 1f. - << QString::number(red, 16) // html wants the hex value here (hence the 16) - << ( (green < 0x10)?"0":"") - << QString::number(green, 16) - << ( (blue < 0x10)?"0":"") - << QString::number(blue, 16) - << "'>"; - } - // we need to reinitialize the bold/italic status, since we closed all the tags - needToReinitializeTags = true; - } - // bold status : - if ( (needToReinitializeTags && charAttributes->fontBold()) || - (!previousCharacterWasBold && charAttributes->fontBold()) ) - // we enter a bold section - outputStream << "<b>"; - if ( !needToReinitializeTags && (previousCharacterWasBold && !charAttributes->fontBold()) ) - // we leave a bold section - outputStream << "</b>"; - - // italic status : - if ( (needToReinitializeTags && charAttributes->fontItalic()) || - (!previousCharacterWasItalic && charAttributes->fontItalic()) ) - // we enter an italic section - outputStream << "<i>"; - if ( !needToReinitializeTags && (previousCharacterWasItalic && !charAttributes->fontItalic()) ) - // we leave an italic section - outputStream << "</i>"; - - // write the actual character : - outputStream << Qt::escape(QString(line.at(curPos))); - - // save status for the next character : - previousCharacterWasItalic = charAttributes->fontItalic(); - previousCharacterWasBold = charAttributes->fontBold(); - previousCharacterColor = charAttributes->foreground().color(); - needToReinitializeTags = false; - } - // Be good citizens and close our tags - if (previousCharacterWasBold) - outputStream << "</b>"; - if (previousCharacterWasItalic) - outputStream << "</i>"; - - if(previousCharacterColor != blackColor) - outputStream << "</span>"; -} - -KateDocument *KateHTMLExporter::document() -{ - return m_view->doc(); -} - -KateRenderer *KateHTMLExporter::renderer() -{ - return m_view->renderer(); -} - -void KateHTMLExporter::exportAsHTML () -{ - KUrl url = KFileDialog::getSaveUrl(document()->documentName(), "text/html", - m_view, i18n("Export File as HTML")); - - if ( url.isEmpty() ) - return; - - QString filename; - - if ( url.isLocalFile() ) - filename = url.toLocalFile(); - else { - KTemporaryFile tmp; // ### only used for network export - tmp.setAutoRemove(false); - tmp.open(); - filename = tmp.fileName(); - } - - KSaveFile savefile(filename); - if (savefile.open()) - { - QTextStream outputStream ( &savefile ); - - //outputStream.setEncoding(QTextStream::UnicodeUTF8); - outputStream.setCodec(QTextCodec::codecForName("UTF-8")); - // let's write the HTML header : - outputStream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; - outputStream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">" << endl; - outputStream << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl; - outputStream << "<head>" << endl; - outputStream << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" << endl; - outputStream << "<meta name=\"Generator\" content=\"Kate, the KDE Advanced Text Editor\" />" << endl; - // for the title, we write the name of the file (/usr/local/emmanuel/myfile.cpp -> myfile.cpp) - outputStream << "<title>" << document()->documentName () << "</title>" << endl; - outputStream << "</head>" << endl; - outputStream << "<body>" << endl; - - textAsHtmlStream(document()->documentRange(), false, outputStream); - - outputStream << "</body>" << endl; - outputStream << "</html>" << endl; - outputStream.flush(); - - savefile.finalize(); //check error? - } -// else -// {/*ERROR*/} - - if ( url.isLocalFile() ) - return; - - KIO::NetAccess::upload( filename, url, 0 ); -} - -// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/utils/katehtmlexporter.h b/kate/utils/katehtmlexporter.h deleted file mode 100644 index 462f8c5..0000000 --- a/kate/utils/katehtmlexporter.h +++ /dev/null @@ -1,93 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2002 John Firebaugh <jfirebaugh@...> - Copyright (C) 2001 Christoph Cullmann <cullmann@...> - Copyright (C) 2001 Joseph Wenninger <jowenn@...> - Copyright (C) 1999 Jochen Wilhelmy <digisnap@...> - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef kate_htmlexporter_h -#define kate_htmlexporter_h - -#include <QtCore/QObject> - -#include <kxmlguiclient.h> - -namespace KTextEditor { - class Range; -} - -class KateDocument; -class KateRenderer; -class KateTextLine; -class KateView; - -class QAction; -class QTextStream; - -class KateHTMLExporter : public QObject, public KXMLGUIClient -{ - Q_OBJECT - - public: - KateHTMLExporter (KateView *view); - ~KateHTMLExporter (); - - public Q_SLOTS: - /** - * internal use, copy text as HTML to clipboard - */ - void copyHTML(); - - void exportAsHTML (); - - private: - QString selectionAsHtml (); - QString textAsHtml (const KTextEditor::Range &range, bool blockwise); - void textAsHtmlStream (const KTextEditor::Range& range, bool blockwise, QTextStream &ts); - - /** - * Gets a substring in valid-xml html. - * Example: "<b>const</b> b = <i>34</i>" - * It won't contain <p> or <body> or <html> or anything like that. - * - * @param startCol start column of substring - * @param length length of substring - * @param renderer The katerenderer. This will have the schema - * information that describes how to render the - * attributes. - * @param outputStream A stream to write the html to - */ - void lineAsHTML (const KateTextLine &line, const int startCol, const int length, QTextStream &outputStream); - - KateDocument *document(); - KateRenderer *renderer(); - - private Q_SLOTS: - /** - * used to update actions after selection changed - */ - void slotUpdateActions(); - - private: - KateView *const m_view; - QAction *m_exportHTML; - QAction *m_copyHTML; -}; - -#endif - -// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/view/kateview.cpp b/kate/view/kateview.cpp index 34d4fde..a6b1b51 100644 --- a/kate/view/kateview.cpp +++ b/kate/view/kateview.cpp @@ -35,7 +35,6 @@ #include "kateviglobal.h" #include "katehighlight.h" #include "katehighlightmenu.h" -#include "katehtmlexporter.h" #include "katedialogs.h" #include "katetextline.h" #include "katecodefolding.h" @@ -252,9 +251,6 @@ KateView::KateView( KateDocument *doc, QWidget *parent ) deactivateEditActions(); showViModeBar(); } - - if (!doc->simpleMode ()) - new KateHTMLExporter(this); } KateView::~KateView() _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceMilian Wolff, 11.11.2009:
> On Wednesday 11 November 2009 20:57:12 Jonathan Schmidt-Dominé - Developer > > wrote: > > Hi! > > > > Signals do not have to be virtual. They use their own dispatching-method > > generated by moc. Signals are not parts of the normal interface- > > implementation-model, declare them like in all the other classes. > > (signals: void bla(); ) > > And don't forget: In C++ Interfaces are like any other class: They need > > space in the object-layout, make this-pointer adjustments necessary..., > > and you can declare anything in the Interface. > > The Interface should not contain private data and > > HighlightInterfacePrivate should not exist because polymorphism for such > > a class would be useless. Let the implementation decide how to save > > information. > > The problem is that the interface is not a Q_OBJECT, hence I can't just add > a "real" signal. The other interfaces really do use pure virtuals, which > is out of the question for the ConfigInterface as it would break BC. I'll > just document it and mark it as TODO for KDE 5 *sigh*. > Please review, else I'll just commit it in the next days so it is in KDE 4.4. I can fix bugs later on. -- Milian Wolff mail@... http://milianw.de _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceMilian Wolff, 12.11.2009:
> On Wednesday 21 October 2009 23:09:43 Dominik Haumann wrote: > > Hi, > > > > after discussions with Milian and Christoph we came up with this: > > > > HighlightInterface: > > // make default styles available > > - enum: DefaultStyles ... all katepart default styles > > - Attribute defaultStyle(DefaultStyle ds); // dsNormalText, ..., > > dsError > > > > // get attribute list of complete line (already in KateTextLine) > > - QVector<KTE::HighlightInterface::AttributeBlock> lineAttributes(int > > line) const; AttributeBlock: > > int: start > > int: length > > Attribute: attribute > > > > // get mode at cursor position > > - QString modeAt(const KTE::Cursor& position) const; > > > > // get all modes in document > > - QStringList modes() const; > > > > > > > > ConfigIterface for KTE::View > > // query background colors > > - value: background-color -> QVariant > > - value: background-selection-color -> QVariant > > Note: has nothing to do with Highlight interface, as it's global > > // emit signal when highlight or config stuff changed > > - signal: emit configChanged(), whenever configEnd is called in the > > KateViewConfig > > Attached you find the three patches that make this all come true: > > 1) the highlight interface, it's implementation, and the porting of the > HTML Exporter to a real plugin to show that the interface works. > > Note: modes() -> embeddedModes() > returns all possible embedded modes, not the default Document::mode() > > Note: lineAttributes returns a QList, since I added a ctor to the > AttributeBlock and hence QVector could not be used. If this is an issue, > tell me and I'll revert. (I just hate structs with no ctor personally :P) > > Also note that the attributes that are returned don't have to span the > whole line. Areas where no highlighting is done, are not covered by the > AttributeBlock. If this should change, tell me. > > Note: I pushed the whole DefaultStyle enum into the interface and used it > across Kate, i.e. the enum from KateExtendedAttribute is gone. > > Note: To implement defaultStyle I pushed some code from the KateHLManager > to its own method so it can be reused easily. But in this method I get the > KColorScheme everytime the method is called. If this is too slow, tell me > and I'll work around it. > > Note: modeAt() returns Document::mode() as a fall-back, should work nicely. > > 2) the background-color & selection-color > note that I called it this way since it's how it was called in KateView > > 3) one for the signal (only documented in the interface, and implemented in > document & view). > > Please review, test and give feedback! sorry - the above is the correct mail to read, not the other one I replied to... -- Milian Wolff mail@... http://milianw.de _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
|
|
Re: HighlightInterfaceOn Thursday 12 November 2009 19:02:29 Milian Wolff wrote:
> On Wednesday 21 October 2009 23:09:43 Dominik Haumann wrote: > > Hi, > > > > after discussions with Milian and Christoph we came up with this: > > > > HighlightInterface: > > // make default styles available > > - enum: DefaultStyles ... all katepart default styles > > - Attribute defaultStyle(DefaultStyle ds); // dsNormalText, ..., > > dsError > > > > // get attribute list of complete line (already in KateTextLine) > > - QVector<KTE::HighlightInterface::AttributeBlock> lineAttributes(int > > line) const; AttributeBlock: > > int: start > > int: length > > Attribute: attribute > > > > // get mode at cursor position > > - QString modeAt(const KTE::Cursor& position) const; > > > > // get all modes in document > > - QStringList modes() const; > > > > > > > > ConfigIterface for KTE::View > > // query background colors > > - value: background-color -> QVariant > > - value: background-selection-color -> QVariant > > Note: has nothing to do with Highlight interface, as it's global > > // emit signal when highlight or config stuff changed > > - signal: emit configChanged(), whenever configEnd is called in the > > KateViewConfig > > Attached you find the three patches that make this all come true: > > 1) the highlight interface, it's implementation, and the porting of the > HTML Exporter to a real plugin to show that the interface works. > > Note: modes() -> embeddedModes() > returns all possible embedded modes, not the default Document::mode() > > Note: lineAttributes returns a QList, since I added a ctor to the > AttributeBlock and hence QVector could not be used. If this is an issue, > tell me and I'll revert. (I just hate structs with no ctor personally :P) > > Also note that the attributes that are returned don't have to span the > whole line. Areas where no highlighting is done, are not covered by the > AttributeBlock. If this should change, tell me. > > Note: I pushed the whole DefaultStyle enum into the interface and used it > across Kate, i.e. the enum from KateExtendedAttribute is gone. > > Note: To implement defaultStyle I pushed some code from the KateHLManager > to its own method so it can be reused easily. But in this method I get the > KColorScheme everytime the method is called. If this is too slow, tell me > and I'll work around it. > > Note: modeAt() returns Document::mode() as a fall-back, should work nicely. > > 2) the background-color & selection-color > note that I called it this way since it's how it was called in KateView > > 3) one for the signal (only documented in the interface, and implemented in > document & view). > > Please review, test and give feedback! -- Milian Wolff mail@... http://milianw.de _______________________________________________ KWrite-Devel mailing list KWrite-Devel@... https://mail.kde.org/mailman/listinfo/kwrite-devel |
| Free embeddable forum powered by Nabble | Forum Help |