Commit 522fb5c5 authored by Michal Humpula's avatar Michal Humpula

project plugin: reformat with astyle-kdelibs

parent 915a9d9e
This diff is collapsed.
......@@ -53,38 +53,37 @@ typedef struct sTagFile tagFile;
/* This structure contains information about the tag file. */
typedef struct {
struct {
/* was the tag file successfully opened? */
int opened;
struct {
/* was the tag file successfully opened? */
int opened;
/* errno value when 'opened' is false */
int error_number;
} status;
/* errno value when 'opened' is false */
int error_number;
} status;
/* information about the structure of the tag file */
struct {
/* format of tag file (1 = original, 2 = extended) */
short format;
/* information about the structure of the tag file */
struct {
/* format of tag file (1 = original, 2 = extended) */
short format;
/* how is the tag file sorted? */
sortType sort;
} file;
/* how is the tag file sorted? */
sortType sort;
} file;
/* information about the program which created this tag file */
struct {
/* name of author of generating program (may be null) */
const char *author;
/* information about the program which created this tag file */
struct {
/* name of author of generating program (may be null) */
const char *author;
/* name of program (may be null) */
const char *name;
/* name of program (may be null) */
const char *name;
/* URL of distribution (may be null) */
const char *url;
/* URL of distribution (may be null) */
const char *url;
/* program version (may be null) */
const char *version;
} program;
/* program version (may be null) */
const char *version;
} program;
} tagFileInfo;
......@@ -93,52 +92,51 @@ typedef struct {
*/
typedef struct {
/* the key of the extension field */
const char *key;
/* the key of the extension field */
const char *key;
/* the value of the extension field (may be an empty string) */
const char *value;
/* the value of the extension field (may be an empty string) */
const char *value;
} tagExtensionField;
/* This structure contains information about a specific tag. */
typedef struct {
/* name of tag */
const char *name;
/* name of tag */
const char *name;
/* path of source file containing definition of tag */
const char *file;
/* path of source file containing definition of tag */
const char *file;
/* address for locating tag in source file */
struct {
/* pattern for locating source line
* (may be NULL if not present) */
const char *pattern;
/* address for locating tag in source file */
struct {
/* pattern for locating source line
* (may be NULL if not present) */
const char *pattern;
/* line number in source file of tag definition
* (may be zero if not known) */
unsigned long lineNumber;
} address;
/* line number in source file of tag definition
* (may be zero if not known) */
unsigned long lineNumber;
} address;
/* kind of tag (may by name, character, or NULL if not known) */
const char *kind;
/* kind of tag (may by name, character, or NULL if not known) */
const char *kind;
/* is tag of file-limited scope? */
short fileScope;
/* is tag of file-limited scope? */
short fileScope;
/* miscellaneous extension fields */
struct {
/* number of entries in `list' */
unsigned short count;
/* miscellaneous extension fields */
struct {
/* number of entries in `list' */
unsigned short count;
/* list of key value pairs */
tagExtensionField *list;
} fields;
/* list of key value pairs */
tagExtensionField *list;
} fields;
} tagEntry;
/*
* FUNCTION PROTOTYPES
*/
......@@ -154,7 +152,7 @@ typedef struct {
* be set to the errno value representing the system error preventing the tag
* file from being successfully opened.
*/
extern tagFile *tagsOpen (const char *const filePath, tagFileInfo *const info);
extern tagFile *tagsOpen(const char *const filePath, tagFileInfo *const info);
/*
* This function allows the client to override the normal automatic detection
......@@ -169,7 +167,7 @@ extern tagFile *tagsOpen (const char *const filePath, tagFileInfo *const info);
* it actually is not. The function will return TagSuccess if called on an
* open tag file or TagFailure if not.
*/
extern tagResult tagsSetSortType (tagFile *const file, const sortType type);
extern tagResult tagsSetSortType(tagFile *const file, const sortType type);
/*
* Reads the first tag in the file, if any. It is passed the handle to an
......@@ -178,7 +176,7 @@ extern tagResult tagsSetSortType (tagFile *const file, const sortType type);
* The function will return TagSuccess another tag entry is found, or
* TagFailure if not (i.e. it reached end of file).
*/
extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry);
extern tagResult tagsFirst(tagFile *const file, tagEntry *const entry);
/*
* Step to the next tag in the file, if any. It is passed the handle to an
......@@ -188,7 +186,7 @@ extern tagResult tagsFirst (tagFile *const file, tagEntry *const entry);
* if not (i.e. it reached end of file). It will always read the first tag in
* the file immediately after calling tagsOpen().
*/
extern tagResult tagsNext (tagFile *const file, tagEntry *const entry);
extern tagResult tagsNext(tagFile *const file, tagEntry *const entry);
/*
* Retrieve the value associated with the extension field for a specified key.
......@@ -197,7 +195,7 @@ extern tagResult tagsNext (tagFile *const file, tagEntry *const entry);
* containing the key of the desired extension field. If no such field of the
* specified key exists, the function will return null.
*/
extern const char *tagsField (const tagEntry *const entry, const char *const key);
extern const char *tagsField(const tagEntry *const entry, const char *const key);
/*
* Find the first tag matching `name'. The structure pointed to by `entry'
......@@ -224,7 +222,7 @@ extern const char *tagsField (const tagEntry *const entry, const char *const key
* The function will return TagSuccess if a tag matching the name is found, or
* TagFailure if not.
*/
extern tagResult tagsFind (tagFile *const file, tagEntry *const entry, const char *const name, const int options);
extern tagResult tagsFind(tagFile *const file, tagEntry *const entry, const char *const name, const int options);
/*
* Find the next tag matching the name and options supplied to the most recent
......@@ -233,14 +231,14 @@ extern tagResult tagsFind (tagFile *const file, tagEntry *const entry, const cha
* function will return TagSuccess if another tag matching the name is found,
* or TagFailure if not.
*/
extern tagResult tagsFindNext (tagFile *const file, tagEntry *const entry);
extern tagResult tagsFindNext(tagFile *const file, tagEntry *const entry);
/*
* Call tagsTerminate() at completion of reading the tag file, which will
* close the file and free any internal memory allocated. The function will
* return TagFailure is no file is currently open, TagSuccess otherwise.
*/
extern tagResult tagsClose (tagFile *const file);
extern tagResult tagsClose(tagFile *const file);
#ifdef __cplusplus
}
......
This diff is collapsed.
......@@ -49,15 +49,13 @@ Q_DECLARE_METATYPE(KateProjectSharedProjectIndex)
class KateProjectWorkerThread : public QThread
{
public:
KateProjectWorkerThread (QObject *worker)
: QThread()
, m_worker (worker)
{
KateProjectWorkerThread(QObject *worker)
: QThread()
, m_worker(worker) {
}
protected:
virtual void run()
{
virtual void run() {
exec();
delete m_worker;
}
......@@ -105,8 +103,7 @@ public:
* Accessor to file name.
* @return file name
*/
const QString &fileName() const
{
const QString &fileName() const {
return m_fileName;
}
......@@ -114,8 +111,7 @@ public:
* Return the base directory of this project.
* @return base directory of project, might not be the directory of the fileName!
*/
const QString &baseDir() const
{
const QString &baseDir() const {
return m_baseDir;
}
......@@ -123,8 +119,7 @@ public:
* Accessor to project map containing the whole project info.
* @return project info
*/
const QVariantMap &projectMap() const
{
const QVariantMap &projectMap() const {
return m_projectMap;
}
......@@ -132,8 +127,7 @@ public:
* Accessor to project name.
* @return project name
*/
QString name() const
{
QString name() const {
return m_projectMap[QStringLiteral("name")].toString();
}
......@@ -141,8 +135,7 @@ public:
* Accessor for the model.
* @return model of this project
*/
QStandardItemModel *model()
{
QStandardItemModel *model() {
return &m_model;
}
......@@ -150,8 +143,7 @@ public:
* Flat list of all files in the project
* @return list of files in project
*/
QStringList files()
{
QStringList files() {
return m_file2Item ? m_file2Item->keys() : QStringList();
}
......@@ -160,8 +152,7 @@ public:
* @param file file to get item for
* @return item for given file or 0
*/
KateProjectItem *itemForFile(const QString &file)
{
KateProjectItem *itemForFile(const QString &file) {
return m_file2Item ? m_file2Item->value(file) : 0;
}
......@@ -171,8 +162,7 @@ public:
* Don't store this pointer, might change.
* @return project index
*/
KateProjectIndex *projectIndex()
{
KateProjectIndex *projectIndex() {
return m_projectIndex.data();
}
......@@ -190,24 +180,24 @@ public:
* @return notes document
*/
QTextDocument *notesDocument();
/**
* Save the notes document to "notes.txt" if any document around.
*/
void saveNotesDocument();
/**
* Register a document for this project.
* @param document document to register
*/
void registerDocument(KTextEditor::Document *document);
/**
* Unregister a document for this project.
* @param document document to unregister
*/
void unregisterDocument(KTextEditor::Document *document);
private Q_SLOTS:
/**
* Used for worker to send back the results of project loading
......@@ -222,13 +212,11 @@ private Q_SLOTS:
*/
void loadIndexDone(KateProjectSharedProjectIndex projectIndex);
void slotModifiedChanged(KTextEditor::Document*);
void slotModifiedChanged(KTextEditor::Document *);
void slotModifiedOnDisk(KTextEditor::Document *document,
bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason);
bool isModified, KTextEditor::ModificationInterface::ModifiedOnDiskReason reason);
Q_SIGNALS:
/**
* Emitted on project map changes.
......@@ -297,17 +285,17 @@ private:
* project index, if any
*/
KateProjectSharedProjectIndex m_projectIndex;
/**
* notes buffer for project local notes
*/
QTextDocument *m_notesDocument;
/**
* Set of existing documents for this project.
*/
QMap<KTextEditor::Document *, QString> m_documents;
/**
* Parent item for existing documents that are not in the project tree
*/
......
This diff is collapsed.
......@@ -33,21 +33,21 @@
*/
class KateProjectCompletion : public KTextEditor::CodeCompletionModel, public KTextEditor::CodeCompletionModelControllerInterface
{
Q_OBJECT
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface)
Q_OBJECT
public:
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface)
public:
/**
* Construct project completion.
* @param plugin our plugin
*/
KateProjectCompletion (class KateProjectPlugin *plugin);
KateProjectCompletion(class KateProjectPlugin *plugin);
/**
* Deconstruct project completion.
*/
~KateProjectCompletion ();
~KateProjectCompletion();
/**
* This function is responsible to generating / updating the list of current
......@@ -59,29 +59,26 @@ class KateProjectCompletion : public KTextEditor::CodeCompletionModel, public KT
* @param view The view to generate completions for
* @param range The range of text to generate completions for
* */
void completionInvoked(KTextEditor::View* view, const KTextEditor::Range& range, InvocationType invocationType);
void completionInvoked(KTextEditor::View *view, const KTextEditor::Range &range, InvocationType invocationType);
bool shouldStartCompletion(KTextEditor::View* view, const QString &insertedText, bool userInsertion, const KTextEditor::Cursor &position);
bool shouldAbortCompletion(KTextEditor::View* view, const KTextEditor::Range &range, const QString &currentCompletion);
bool shouldStartCompletion(KTextEditor::View *view, const QString &insertedText, bool userInsertion, const KTextEditor::Cursor &position);
bool shouldAbortCompletion(KTextEditor::View *view, const KTextEditor::Range &range, const QString &currentCompletion);
void saveMatches( KTextEditor::View* view,
const KTextEditor::Range& range);
void saveMatches(KTextEditor::View *view,
const KTextEditor::Range &range);
int rowCount ( const QModelIndex & parent ) const;
int rowCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex& index, int role) const;
virtual QModelIndex index(int row, int column, const QModelIndex& parent=QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex& index) const;
virtual MatchReaction matchingItem(const QModelIndex& matched);
QVariant data(const QModelIndex &index, int role) const;
virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex &index) const;
virtual MatchReaction matchingItem(const QModelIndex &matched);
virtual KTextEditor::Range completionRange(KTextEditor::View* view, const KTextEditor::Cursor &position);
virtual KTextEditor::Range completionRange(KTextEditor::View *view, const KTextEditor::Cursor &position);
void allMatches( QStandardItemModel &model, KTextEditor::View *view, const KTextEditor::Range &range ) const;
void allMatches(QStandardItemModel &model, KTextEditor::View *view, const KTextEditor::Range &range) const;
private:
private:
/**
* our plugin view
*/
......@@ -91,7 +88,7 @@ class KateProjectCompletion : public KTextEditor::CodeCompletionModel, public KT
* model with matching data
*/
QStandardItemModel m_matches;
/**
* automatic invocation?
*/
......@@ -100,4 +97,3 @@ class KateProjectCompletion : public KTextEditor::CodeCompletionModel, public KT
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
......@@ -28,166 +28,174 @@
*/
#include "ctags/readtags.c"
KateProjectIndex::KateProjectIndex (const QStringList &files)
: m_ctagsIndexFile (QDir::tempPath () + QStringLiteral("/kate.project.ctags"))
, m_ctagsIndexHandle (0)
KateProjectIndex::KateProjectIndex(const QStringList &files)
: m_ctagsIndexFile(QDir::tempPath() + QStringLiteral("/kate.project.ctags"))
, m_ctagsIndexHandle(0)
{
/**
* load ctags
*/
loadCtags (files);
/**
* load ctags
*/
loadCtags(files);
}
KateProjectIndex::~KateProjectIndex ()
KateProjectIndex::~KateProjectIndex()
{
/**
* delete ctags handle if any
*/
if (m_ctagsIndexHandle) {
tagsClose (m_ctagsIndexHandle);
m_ctagsIndexHandle = 0;
}
/**
* delete ctags handle if any
*/
if (m_ctagsIndexHandle) {
tagsClose(m_ctagsIndexHandle);
m_ctagsIndexHandle = 0;
}
}
void KateProjectIndex::loadCtags (const QStringList &files)
void KateProjectIndex::loadCtags(const QStringList &files)
{
/**
* create temporary file
* if not possible, fail
*/
if (!m_ctagsIndexFile.open ())
return;
/**
* close file again, other process will use it
*/
m_ctagsIndexFile.close ();
/**
* try to run ctags for all files in this project
* output to our ctags index file
*/
QProcess ctags;
QStringList args;
args << QStringLiteral("-L") << QStringLiteral("-") << QStringLiteral("-f") << m_ctagsIndexFile.fileName() << QStringLiteral("--fields=+K+n");
ctags.start(QStringLiteral("ctags"), args);
if (!ctags.waitForStarted())
return;
/**
* write files list and close write channel
*/
ctags.write(files.join(QStringLiteral("\n")).toLocal8Bit());
ctags.closeWriteChannel();
/**
* wait for done
*/
if (!ctags.waitForFinished())
return;
/**
* file not openable, bad
*/
if (!m_ctagsIndexFile.open ())
return;
/**
* get size
*/
qint64 size = m_ctagsIndexFile.size ();
/**
* close again
*/
m_ctagsIndexFile.close ();
/**
* empty file, bad
*/
if (!size)
return;
/**
* try to open ctags file
*/
tagFileInfo info;
memset (&info, 0, sizeof (tagFileInfo));
m_ctagsIndexHandle = tagsOpen (m_ctagsIndexFile.fileName().toLocal8Bit().constData(), &info);
/**
* create temporary file
* if not possible, fail
*/
if (!m_ctagsIndexFile.open()) {
return;
}
/**
* close file again, other process will use it
*/
m_ctagsIndexFile.close();
/**
* try to run ctags for all files in this project
* output to our ctags index file
*/
QProcess ctags;
QStringList args;
args << QStringLiteral("-L") << QStringLiteral("-") << QStringLiteral("-f") << m_ctagsIndexFile.fileName() << QStringLiteral("--fields=+K+n");
ctags.start(QStringLiteral("ctags"), args);
if (!ctags.waitForStarted()) {
return;
}
/**
* write files list and close write channel
*/
ctags.write(files.join(QStringLiteral("\n")).toLocal8Bit());
ctags.closeWriteChannel();
/**
* wait for done
*/
if (!ctags.waitForFinished()) {
return;
}
/**
* file not openable, bad
*/
if (!m_ctagsIndexFile.open()) {
return;
}
/**
* get size
*/
qint64 size = m_ctagsIndexFile.size();
/**
* close again
*/
m_ctagsIndexFile.close();
/**
* empty file, bad
*/
if (!size) {
return;
}
/**
* try to open ctags file
*/
tagFileInfo info;
memset(&info, 0, sizeof(tagFileInfo));
m_ctagsIndexHandle = tagsOpen(m_ctagsIndexFile.fileName().toLocal8Bit().constData(), &info);
}
void KateProjectIndex::findMatches (QStandardItemModel &model, const QString &searchWord, MatchType type)
void KateProjectIndex::findMatches(QStandardItemModel &model, const QString &searchWord, MatchType type)
{
/**
* abort if no ctags index
*/
if (!m_ctagsIndexHandle)
return;
/**
* word to complete
* abort if empty
*/
QByteArray word = searchWord.toLocal8Bit();
if (word.isEmpty())
return;
/**
* try to search entry
* fail if none found
*/
tagEntry entry;
if (tagsFind (m_ctagsIndexHandle, &entry, word.constData(), TAG_PARTIALMATCH | TAG_OBSERVECASE) != TagSuccess)
return;
/**
* set to show words only once for completion matches
*/
QSet<QString> guard;
/**
* loop over all found tags
* first one is filled by above find, others by find next
*/
do {
/**
* skip if no name
*/
if (!entry.name)
continue;
/**
* get name
*/
QString name (QString::fromLocal8Bit(entry.name));
/**
* construct right items
*/
switch (type) {
case CompletionMatches:
/**
* abort if no ctags index
*/
if (!m_ctagsIndexHandle) {
return;
}
/**
* word to complete
* abort if empty
*/
QByteArray word = searchWord.toLocal8Bit();
if (word.isEmpty()) {
return;
}
/**
* try to search entry
* fail if none found
*/
tagEntry entry;
if (tagsFind(m_ctagsIndexHandle, &entry, word.constData(), TAG_PARTIALMATCH | TAG_OBSERVECASE) != TagSuccess) {
return;
}
/**
* set to show words only once for completion matches
*/
QSet<QString> guard;
/**
* loop over all found tags
* first one is filled by above find, others by find next
*/
do {
/**
* add new completion item, if new name
* skip if no name
*/
if (!guard.contains (name)) {
model.appendRow (new QStandardItem (name));
guard.insert (name);
if (!entry.name) {