scide: cancel ScRequests when recompiling the class library
[supercollider.git] / editors / sc-ide / widgets / sc_symbol_references.cpp
blob8264adf71fedb1a9776a50d03c657570969c6048
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 #include <QHeaderView>
23 #include "sc_symbol_references.hpp"
24 #include "../core/main.hpp"
25 #include "../core/sc_introspection.hpp"
27 #include "yaml-cpp/node.h"
28 #include "yaml-cpp/parser.h"
30 using namespace ScIDE;
32 ReferencesDialog::ReferencesDialog(QWidget * parent):
33 LookupDialog(parent)
35 setWindowTitle(tr("Look Up References"));
37 mQueryEdit->setText(tr("Enter symbol to find references"));
38 mQueryEdit->selectAll();
41 void ReferencesDialog::performQuery()
43 QString queryString = mQueryEdit->text();
45 if (queryString.isEmpty()) {
46 mResult->setModel(NULL);
47 return;
50 SymbolReferenceRequest * request = new SymbolReferenceRequest(Main::scProcess(), this);
51 connect(request, SIGNAL(response(QString,QString)), this, SLOT(onResposeFromLanguage(QString,QString)));
52 connect(request, SIGNAL(requestCanceled()), this, SLOT(requestCanceled()));
53 request->sendRequest(queryString);
56 void ReferencesDialog::requestCanceled()
58 mResult->setModel(NULL);
61 void ReferencesDialog::onResposeFromLanguage(const QString &, const QString &responseData)
63 QStandardItemModel * model = parse(responseData);
64 mResult->setModel(model);
66 if (model)
67 focusResults();
70 QStandardItemModel * ReferencesDialog::parse(const QString &responseData)
72 using namespace ScLanguage;
73 const Introspection & introspection = Main::scProcess()->introspection();
75 if (!introspection.introspectionAvailable()) {
76 qWarning() << "Introspection not available"; // just required for short path name
77 return NULL;
80 std::stringstream stream;
81 stream << responseData.toStdString();
82 YAML::Parser parser(stream);
84 YAML::Node doc;
85 if(!parser.GetNextDocument(doc)) {
86 qWarning("no YAML document");
87 return NULL;
90 assert (doc.Type() == YAML::NodeType::Sequence);
92 QString symbol = doc[0].to<std::string>().c_str();
94 QStandardItemModel * model = new QStandardItemModel(this);
95 QStandardItem *parentItem = model->invisibleRootItem();
97 YAML::Node const & references = doc[1];
99 for (YAML::Iterator refIt = references.begin(); refIt != references.end(); ++refIt ) {
100 YAML::Node const & reference = *refIt;
101 QString className = reference[0].to<std::string>().c_str();
102 QString methodName = reference[1].to<std::string>().c_str();
103 QString path = reference[2].to<std::string>().c_str();
104 int charPos = reference[3].to<int>();
106 QString displayPath = introspection.compactLibraryPath(path);
107 QString fullName = ScLanguage::makeFullMethodName(className, methodName);
109 parentItem->appendRow(makeDialogItem(fullName, displayPath, path, charPos));
112 return model;