Merge pull request #113 from Atlante45/feat/atp

Fix drag&drop
This commit is contained in:
Stephen Birarda 2016-03-15 14:36:37 -07:00
commit 42d7bc4263
5 changed files with 43 additions and 26 deletions

View file

@ -45,6 +45,7 @@ Window {
}
Component.onCompleted: {
ApplicationInterface.uploadRequest.connect(uploadClicked);
assetMappingsModel.errorGettingMappings.connect(handleGetMappingsError);
reload();
}
@ -245,24 +246,14 @@ Window {
Timer {
id: timer
}
function uploadClicked() {
function uploadClicked(fileUrl) {
if (uploadOpen) {
return;
}
uploadOpen = true;
var fileUrl = "";
var browser = desktop.fileDialog({
selectDirectory: false,
dir: currentDirectory
});
browser.canceled.connect(function() {
uploadOpen = false;
});
browser.selectedFile.connect(function(url){
function doUpload(url, dropping) {
var fileUrl = fileDialogHelper.urlToPath(url);
currentDirectory = browser.dir;
var path = assetProxyModel.data(treeView.selection.currentIndex, 0x100);
var directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : "/";
@ -299,8 +290,24 @@ Window {
uploadButton.enabled = true;
uploadOpen = false;
}
})
});
}, dropping);
}
if (fileUrl) {
doUpload(fileUrl, true);
} else {
var browser = desktop.fileDialog({
selectDirectory: false,
dir: currentDirectory
});
browser.canceled.connect(function() {
uploadOpen = false;
});
browser.selectedFile.connect(function(url) {
currentDirectory = browser.dir;
doUpload(url, false);
});
}
}
function errorMessageBox(message) {
@ -312,10 +319,6 @@ Window {
});
}
function itemSelected() {
return treeView.selection.hasSelection()
}
Item {
width: pane.contentWidth
height: pane.height
@ -457,7 +460,6 @@ Window {
height: 30
width: 155
enabled: fileUrlTextField.text != ""
onClicked: uploadClickedTimer.running = true
// For some reason trigginer an API that enters

View file

@ -4455,11 +4455,18 @@ void Application::toggleRunningScriptsWidget() {
}
void Application::toggleAssetServerWidget(QString filePath) {
if (!DependencyManager::get<NodeList>()->getThisNodeCanRez()) {
return;
}
static const QUrl url("AssetServer.qml");
auto urlSetter = [=](QQmlContext* context, QObject* newObject){
newObject->setProperty("currentFileUrl", filePath);
auto startUpload = [=](QQmlContext* context, QObject* newObject){
if (!filePath.isEmpty()) {
emit uploadRequest(filePath);
}
};
DependencyManager::get<OffscreenUi>()->show(url, "AssetServer", urlSetter);
DependencyManager::get<OffscreenUi>()->show(url, "AssetServer", startUpload);
startUpload(nullptr, nullptr);
}
void Application::packageModel() {

View file

@ -231,6 +231,8 @@ signals:
void beforeAboutToQuit();
void activeDisplayPluginChanged();
void uploadRequest(QString path);
public slots:
QVector<EntityItemID> pasteEntities(float x, float y, float z);
bool exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs);

View file

@ -59,13 +59,18 @@ void AssetMappingsScriptingInterface::getMapping(QString path, QJSValue callback
request->start();
}
void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, QJSValue startedCallback, QJSValue completedCallback) {
void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, QJSValue startedCallback, QJSValue completedCallback, bool dropEvent) {
static const QString helpText =
"Upload your asset to a specific folder by entering the full path. Specifying "
"Upload your asset to a specific folder by entering the full path. Specifying\n"
"a new folder name will automatically create that folder for you.";
static const QString dropHelpText =
"This file will be added to your Asset Server.\n"
"Use the field below to place your file in a specific folder or to rename it.\n"
"Specifying a new folder name will automatically create that folder for you.";
auto offscreenUi = DependencyManager::get<OffscreenUi>();
auto result = offscreenUi->inputDialog(OffscreenUi::ICON_INFORMATION, "Specify Asset Path", helpText, mapping);
auto result = offscreenUi->inputDialog(OffscreenUi::ICON_INFORMATION, "Specify Asset Path",
dropEvent ? dropHelpText : helpText, mapping);
if (!result.isValid()) {
completedCallback.call({ -1 });

View file

@ -30,6 +30,7 @@ public:
bool isKnownMapping(QString path) const { return _pathToItemMap.contains(path); }
bool isKnownFolder(QString path) const;
signals:
void errorGettingMappings(QString errorString);
private:
@ -53,7 +54,7 @@ public:
Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback = QJSValue());
Q_INVOKABLE void getMapping(QString path, QJSValue callback = QJSValue());
Q_INVOKABLE void uploadFile(QString path, QString mapping, QJSValue startedCallback = QJSValue(), QJSValue completedCallback = QJSValue());
Q_INVOKABLE void uploadFile(QString path, QString mapping, QJSValue startedCallback = QJSValue(), QJSValue completedCallback = QJSValue(), bool dropEvent = false);
Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback);
Q_INVOKABLE void deleteMapping(QString path, QJSValue callback) { deleteMappings(QStringList(path), callback = QJSValue()); }
Q_INVOKABLE void getAllMappings(QJSValue callback = QJSValue());