Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / editors / sc-ide / widgets / lookup_dialog.hpp
blobdffc25c3a8ed86fe03644dd0a4ac7e6297d7e90f
1 /*
2 SuperCollider Qt IDE
3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_WIDGETS_LOOKUP_DIALOG_HPP_INCLUDED
22 #define SCIDE_WIDGETS_LOOKUP_DIALOG_HPP_INCLUDED
24 #include <QDialog>
25 #include <QLineEdit>
26 #include <QStandardItemModel>
27 #include <QTreeWidget>
29 #include "../core/sc_process.hpp"
31 namespace ScIDE {
33 class LookupDialogTreeView : public QTreeView
35 Q_OBJECT
37 public:
38 LookupDialogTreeView(QWidget * parent): QTreeView(parent) {}
40 public Q_SLOTS:
41 bool openDocumentation();
44 class GenericLookupDialog: public QDialog
46 Q_OBJECT
48 public:
49 static const int PathRole = Qt::UserRole + 1;
50 static const int CharPosRole = Qt::UserRole + 2;
51 static const int IsClassRole = Qt::UserRole + 3;
52 static const int ClassNameRole = Qt::UserRole + 4;
53 static const int MethodNameRole = Qt::UserRole + 5;
55 explicit GenericLookupDialog(QWidget *parent = 0);
56 void query( const QString & query ) { mQueryEdit->setText(query); this->performQuery(); }
57 void clearQuery() { mQueryEdit->clear(); }
59 public Q_SLOTS:
60 void openDocumentation();
62 protected Q_SLOTS:
63 virtual void onAccepted(QModelIndex);
65 private Q_SLOTS:
66 virtual void performQuery() = 0;
68 protected:
69 QStandardItem * firstItemInLine(QModelIndex);
70 bool eventFilter( QObject *, QEvent * );
71 void paintEvent( QPaintEvent * );
72 void focusResults();
74 static QList<QStandardItem *> makeDialogItem(QString const & displayString, QString const & displayPath,
75 QString const & path, int position,
76 QString const & className, QString const & methodName,
77 bool isClassItem);
79 LookupDialogTreeView *mResult;
80 QLineEdit *mQueryEdit;
83 class LookupDialog : public GenericLookupDialog
85 Q_OBJECT
87 public:
88 explicit LookupDialog(QWidget *parent = 0);
90 private slots:
91 void performQuery();
92 void onAccepted(QModelIndex);
94 private:
95 QStandardItemModel * modelForClass(const QString & className);
96 QStandardItemModel * modelForMethod(const QString & methodName);
97 QStandardItemModel * modelForPartialQuery(const QString & queryString);
98 bool performClassQuery(const QString & className);
99 bool performMethodQuery(const QString & methodName);
100 bool performPartialQuery(const QString & queryString);
102 bool mIsPartialQuery;
105 // LATER: cache symbol references to avoid duplicate lookup
106 class SymbolReferenceRequest:
107 public ScRequest
109 Q_OBJECT
111 public:
112 SymbolReferenceRequest(SCProcess * process, QObject * parent = NULL):
113 ScRequest(process, parent)
116 void sendRequest(QString const & symbol)
118 send("findReferencesToSymbol", symbol);
122 class ReferencesDialog:
123 public LookupDialog
125 Q_OBJECT
127 public:
128 explicit ReferencesDialog(QWidget * parent = NULL);
130 private slots:
131 void requestCanceled();
132 void performQuery();
133 void onResposeFromLanguage(const QString &command, const QString &responseData);
134 QStandardItemModel * parse(QString const & responseData);
137 } // namespace ScIDE
139 #endif // SCIDE_WIDGETS_LOOKUP_DIALOG_HPP_INCLUDED