Skip to content

Commit

Permalink
re #8450 drop drop workspace names to ipython
Browse files Browse the repository at this point in the history
  • Loading branch information
NickDraper committed Nov 25, 2013
1 parent 95c33cb commit ff6fdb7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,8 @@ void InstrumentWindow::setViewType(const QString& type)

void InstrumentWindow::dragEnterEvent( QDragEnterEvent* e )
{
QString text = e->mimeData()->text();
if (text.startsWith("Workspace::"))
QString name = e->mimeData()->objectName();
if (name == "MantidWorkspace")
{
e->accept();
}
Expand All @@ -1028,11 +1028,23 @@ void InstrumentWindow::dragEnterEvent( QDragEnterEvent* e )

void InstrumentWindow::dropEvent( QDropEvent* e )
{
QString text = e->mimeData()->text();
if (text.startsWith("Workspace::"))
QString name = e->mimeData()->objectName();
if (name == "MantidWorkspace")
{
QStringList wsName = text.split("::");
if(this->overlay(wsName[1])) e->accept();
QString text = e->mimeData()->text();
int endIndex = 0;
QStringList wsNames;
while (text.indexOf("[\"",endIndex) > -1)
{
int startIndex = text.indexOf("[\"",endIndex) + 2;
endIndex = text.indexOf("\"]",startIndex);
wsNames.append(text.mid(startIndex,endIndex-startIndex));
}

for (const auto wsName: wsNames)
{
if(this->overlay(wsName)) e->accept();
}
}
e->ignore();
}
Expand Down
14 changes: 13 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <Poco/Path.h>

#include <algorithm>
#include <sstream>

using namespace Mantid::API;
using namespace Mantid::Kernel;
Expand Down Expand Up @@ -1241,7 +1242,18 @@ void MantidTreeWidget::mouseMoveEvent(QMouseEvent *e)

QStringList wsnames = getSelectedWorkspaceNames();
if (wsnames.size() == 0) return;
mimeData->setText("Workspace::"+getSelectedWorkspaceNames()[0]);
QString importStatement = "";
foreach( const QString wsname, wsnames )
{
QString prefix = "";
if (wsname[0].isDigit()) prefix = "ws";
if (importStatement.size() > 0) importStatement += "\n";
importStatement += prefix + wsname + " = mtd[\"" + wsname + "\"]";
}

mimeData->setText(importStatement);
mimeData->setObjectName("MantidWorkspace");

drag->setMimeData(mimeData);

Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
Expand Down
19 changes: 16 additions & 3 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,10 +1228,23 @@ Table* MantidUI::createDetectorTable(const QString & wsName, const Mantid::API::

bool MantidUI::drop(QDropEvent* e)
{
if (e->source() == m_exploreMantid->m_tree)
QString name = e->mimeData()->objectName();
if (name == "MantidWorkspace")
{
QString wsName = getSelectedWorkspaceName();
importWorkspace(wsName,false);
QString text = e->mimeData()->text();
int endIndex = 0;
QStringList wsNames;
while (text.indexOf("[\"",endIndex) > -1)
{
int startIndex = text.indexOf("[\"",endIndex) + 2;
endIndex = text.indexOf("\"]",startIndex);
wsNames.append(text.mid(startIndex,endIndex-startIndex));
}

for (const auto wsName: wsNames)
{
importWorkspace(wsName,false);
}
return true;
}

Expand Down
31 changes: 3 additions & 28 deletions Code/Mantid/MantidQt/MantidWidgets/src/ScriptEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,6 @@ void ScriptEditor::updateCompletionAPI(const QStringList & keywords)
*/
void ScriptEditor::dragMoveEvent(QDragMoveEvent *de)
{
// The event needs to be accepted here
if (de->mimeData()->text().startsWith("Workspace::"))
de->accept();
if(!de->mimeData()->hasUrls())
//pass to base class - This handles text appropriately
QsciScintilla::dragMoveEvent(de);
Expand All @@ -507,9 +504,6 @@ void ScriptEditor::dragMoveEvent(QDragMoveEvent *de)
*/
void ScriptEditor::dragEnterEvent(QDragEnterEvent *de)
{
// Set the drop action to be the proposed action.
if (de->mimeData()->text().startsWith("Workspace::"))
de->acceptProposedAction();
if(!de->mimeData()->hasUrls())
//pass to base class - This handles text appropriately
QsciScintilla::dragEnterEvent(de);
Expand All @@ -521,32 +515,13 @@ void ScriptEditor::dragEnterEvent(QDragEnterEvent *de)
*/
void ScriptEditor::dropEvent(QDropEvent *de)
{
const QString WORKSPACE_PREFIX = "Workspace::";

QStringList filenames;
const QMimeData *mimeData = de->mimeData();
if(!mimeData->hasUrls())
{
if(mimeData->text().startsWith(WORKSPACE_PREFIX) )
{
int line, index;
this->getCursorPosition(&line,&index);
QMimeData myMimeData;
QString wsName = mimeData->text().mid(WORKSPACE_PREFIX.size());
QString importStatement = wsName + " = mtd[\"" + wsName + "\"]\n";
myMimeData.setText(importStatement);

QDropEvent myDropEvent(de->pos(),de->possibleActions(),&myMimeData, de->mouseButtons(),de->keyboardModifiers(),de->type());
QsciScintilla::dropEvent(&myDropEvent);
de->acceptProposedAction();
//this->insertAt(importStatement,line,index);
}
else
{
//pass to base class - This handles text appropriately
QsciScintilla::dropEvent(de);
}
}
//pass to base class - This handles text appropriately
QsciScintilla::dropEvent(de);
}
}

/**
Expand Down

0 comments on commit ff6fdb7

Please sign in to comment.