completion.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2006-2007 Kevin Kofler
  4. Copyright (C) 2007 Konrad Meyer
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program 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
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #pragma once
  18. #include <QObject>
  19. #include <Q3PopupMenu>
  20. #include <QMap>
  21. #include <QString>
  22. #include <QStringList>
  23. #include <Q3ValueList>
  24. #include <QList>
  25. #include <QEvent>
  26. #include <ktexteditor/view.h>
  27. #include <ktexteditor/codecompletionmodel.h>
  28. struct CompletionEntry
  29. {
  30. QString type;
  31. QString text;
  32. QString prefix;
  33. QString postfix;
  34. QString comment;
  35. QString userdata;
  36. bool operator==( const CompletionEntry &c ) const {
  37. return c.type == type
  38. && c.text == text
  39. && c.postfix == postfix
  40. && c.prefix == prefix
  41. && c.comment == comment
  42. && c.userdata == userdata;
  43. }
  44. };
  45. struct CompletionInfo {
  46. CompletionInfo() : dirty(false), searched(false) {}
  47. bool dirty;
  48. bool searched;
  49. QStringList includedSystem;
  50. QStringList included;
  51. QMap<QString,unsigned> lineNumbers;
  52. QList<CompletionEntry> entries;
  53. };
  54. // Maps file name to a CompletionInfo.
  55. extern QMap<QString,CompletionInfo> systemHeaderCompletion, projectCompletion;
  56. class MainForm;
  57. bool findSymbolInFile(const QString &symbol,
  58. const QString &fileText,
  59. const QString &fileName,
  60. MainForm *mainForm,
  61. QString &symbolFile,
  62. unsigned &symbolLine,
  63. bool &systemHeader);
  64. bool completionEntriesForFile(const QString &fileText,
  65. const QString &fileName,
  66. MainForm *mainForm,
  67. QList<CompletionEntry> &result);
  68. class QWidget;
  69. bool parseHelpSources(QWidget *parent, const QString &directory,
  70. QMap<QString,CompletionInfo> &sysHdrCompletion);
  71. bool parseSystemHeaders(QWidget *parent, const QString &directory,
  72. QMap<QString,CompletionInfo> &sysHdrCompletion);
  73. void loadSystemHeaderCompletion(void);
  74. void saveSystemHeaderCompletion(void);
  75. class TemplatePopup : public Q3PopupMenu {
  76. Q_OBJECT
  77. public:
  78. TemplatePopup(KTextEditor::View *parent);
  79. virtual ~TemplatePopup() {}
  80. private slots:
  81. void QPopupMenu_activated(int id);
  82. private:
  83. KTextEditor::View *view;
  84. };
  85. class CompletionModel : public KTextEditor::CodeCompletionModel
  86. {
  87. Q_OBJECT
  88. public:
  89. CompletionModel(QObject *parent, const QList<CompletionEntry> &entries);
  90. ~CompletionModel();
  91. virtual int rowCount(const QModelIndex &parent) const;
  92. virtual QModelIndex index(int row, int column,
  93. const QModelIndex &parent=QModelIndex()) const;
  94. virtual QVariant data(const QModelIndex &index, int role) const;
  95. private:
  96. const QList<CompletionEntry> m_entries;
  97. };
  98. class QEvent;
  99. class QWidget;
  100. class CompletionPopup : public QObject {
  101. Q_OBJECT
  102. public:
  103. CompletionPopup(KTextEditor::View *parent, const QString &fileName,
  104. MainForm *mainForm, QObject *receiver);
  105. virtual ~CompletionPopup() {}
  106. private slots:
  107. void slotDone();
  108. signals:
  109. void closed();
  110. private:
  111. bool done;
  112. QWidget *completionPopup;
  113. };
  114. class ArgHintPopup : public QObject {
  115. Q_OBJECT
  116. public:
  117. ArgHintPopup(KTextEditor::View *parent, const QString &fileName,
  118. MainForm *mainForm);
  119. virtual ~ArgHintPopup() {}
  120. private slots:
  121. void slotDone();
  122. protected:
  123. bool eventFilter(QObject *o, QEvent *e);
  124. private:
  125. bool done;
  126. QWidget *argHintPopup;
  127. };