1 /* This file is part of KDevelop
2 Copyright (C) 2008 Cédric Pasteur <cedric.pasteur@free.fr>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef SOURCEFORMATTERPLUGIN_H
21 #define SOURCEFORMATTERPLUGIN_H
38 #include <interfaces/iplugin.h>
40 class ISourceFormatter
;
45 class ContextMenuExtension
;
46 class ProjectBaseItem
;
49 /** \short A plugin to format and beautify source files
50 * It can support any backend using plugins implementing
51 * the \ref ISourceFormatter interface.
53 class SourceFormatterPlugin
: public KDevelop::IPlugin
58 SourceFormatterPlugin(QObject
*parent
, const QVariantList
&args
= QVariantList());
59 virtual ~SourceFormatterPlugin();
61 KDevelop::ContextMenuExtension
contextMenuExtension(KDevelop::Context
* context
);
63 void formatFiles(KUrl::List
&list
);
66 /** Formats the file in the currently active document, or only
67 * the selected part if a selection exists. In this case, the indentation of
68 * the selection is kept.
70 void beautifySource();
71 /** Formats the items in m_prjItems or m_urls.
76 /** Formats the document corresponding to \arg doc , using \arg formatter.
77 * \arg mime is the mime type of the file. The content of the editor is
78 * modified but the file is not saved.
80 void formatDocument(KDevelop::IDocument
*doc
, ISourceFormatter
*formatter
,
81 const KMimeType::Ptr
&mime
);
82 /** Replaces spaces with tabs using the number of spaces per tabs defined
83 * in the \arg formatter or convert tabs to spaces, depending on the config.
84 * \return The modified string
86 QString
replaceSpacesWithTab(const QString
&input
, ISourceFormatter
*formatter
);
87 /** Adds the string \arg indentWith at the beginning of each line in \arg input.
88 * \return The modified string
90 QString
addIndentation(QString input
, const QString indentWith
);
93 void activePartChanged(KParts::Part
*part
);
96 KAction
*m_formatTextAction
;
97 KAction
*m_formatFilesAction
;
100 QList
<KDevelop::ProjectBaseItem
*> m_prjItems
;
103 #endif // SOURCEFORMATTERPLUGIN_H
105 // kate: indent-mode cstyle; space-indent off; tab-width 4;