Add mapping sorting, copying, and isKnownMapping

This commit is contained in:
Ryan Huffman 2016-03-10 08:18:17 -08:00
parent 5a39718645
commit 3e5e2eef17
5 changed files with 62 additions and 13 deletions

View file

@ -33,7 +33,7 @@ Window {
HifiConstants { id: hifi }
property var scripts: ScriptDiscoveryService;
property var scriptsModel: Assets.mappingModel;
property var assetMappingsModel: Assets.proxyModel;
property var currentDirectory;
property alias currentFileUrl: fileUrlTextField.text;
@ -67,8 +67,8 @@ Window {
});
}
function fileExists(destinationPath) {
return true; // TODO get correct value
function fileExists(path) {
return Assets.isKnownMapping(path);
}
function askForOverride(path, callback) {
@ -89,7 +89,7 @@ Window {
function canAddToWorld() {
var supportedExtensions = [/\.fbx\b/i, /\.obj\b/i];
var path = scriptsModel.data(treeView.currentIndex, 0x100);
var path = assetMappingsModel.data(treeView.currentIndex, 0x100);
return supportedExtensions.reduce(function(total, current) {
return total | new RegExp(current).test(path);
@ -98,18 +98,25 @@ Window {
function reload() {
print("reload");
scriptsModel.refresh();
Assets.mappingModel.refresh();
}
function addToWorld() {
var path = scriptsModel.data(treeView.currentIndex, 0x100);
var path = assetMappingsModel.data(treeView.currentIndex, 0x100);
if (!path) {
return;
}
print("addToWorld");
}
function copyURLToClipboard() {
var path = assetMappingsModel.data(treeView.currentIndex, 0x103);
if (!path) {
return;
}
Window.copyToClipboard(path);
}
function renameFile() {
var path = scriptsModel.data(treeView.currentIndex, 0x100);
var path = assetMappingsModel.data(treeView.currentIndex, 0x100);
if (!path) {
return;
}
@ -120,6 +127,9 @@ Window {
placeholderText: "Enter path here"
});
object.selected.connect(function(destinationPath) {
if (path == destinationPath) {
return;
}
if (fileExists(destinationPath)) {
askForOverride(destinationPath, function() {
doRenameFile(path, destinationPath);
@ -130,17 +140,20 @@ Window {
});
}
function deleteFile() {
var path = scriptsModel.data(treeView.currentIndex, 0x100);
var path = assetMappingsModel.data(treeView.currentIndex, 0x100);
if (!path) {
return;
}
var isFolder = assetMappingsModel.data(treeView.currentIndex, 0x101);
var typeString = isFolder ? 'folder' : 'file';
var object = desktop.messageBox({
icon: OriginalDialogs.StandardIcon.Question,
buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No,
defaultButton: OriginalDialogs.StandardButton.No,
text: "Deleting",
informativeText: "You are about to delete the following file:\n" +
informativeText: "You are about to delete the following " + typeString + ":\n" +
path +
"\nDo you want to continue?"
});
@ -166,7 +179,7 @@ Window {
var fileUrl = fileUrlTextField.text
var addToWorld = addToWorldCheckBox.checked
var path = scriptsModel.data(treeView.currentIndex, 0x100);
var path = assetMappingsModel.data(treeView.currentIndex, 0x100);
var directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : "";
var filename = fileUrl.slice(fileUrl.lastIndexOf('/') + 1);
@ -211,6 +224,16 @@ Window {
onClicked: root.reload()
}
HifiControls.GlyphButton {
glyph: hifi.glyphs.reload
color: hifi.buttons.white
colorScheme: root.colorScheme
height: 26
width: 26
onClicked: root.copyURLToClipboard()
}
HifiControls.Button {
text: "ADD TO WORLD"
color: hifi.buttons.white
@ -249,7 +272,7 @@ Window {
HifiControls.Tree {
id: treeView
height: 400
treeModel: scriptsModel
treeModel: assetMappingsModel
colorScheme: root.colorScheme
anchors.left: parent.left
anchors.right: parent.right

View file

@ -9,6 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QClipboard>
#include <QtCore/QDir>
#include <QMessageBox>
#include <QScriptValue>
@ -139,3 +140,8 @@ int WindowScriptingInterface::getX() {
int WindowScriptingInterface::getY() {
return qApp->getWindow()->y();
}
void WindowScriptingInterface::copyToClipboard(const QString& text) {
qDebug() << "Copying";
QApplication::clipboard()->setText(text);
}

View file

@ -40,6 +40,7 @@ public slots:
QScriptValue prompt(const QString& message = "", const QString& defaultText = "");
QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
QScriptValue save(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
void copyToClipboard(const QString& text);
signals:
void domainChanged(const QString& domainHostname);

View file

@ -18,6 +18,13 @@
#include <MappingRequest.h>
#include <NetworkLogging.h>
AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() {
_proxyModel.setSourceModel(&_assetMappingModel);
_proxyModel.setSortRole(Qt::DisplayRole);
_proxyModel.setDynamicSortFilter(true);
_proxyModel.sort(0);
}
void AssetMappingsScriptingInterface::setMapping(QString path, QString hash, QJSValue callback) {
auto assetClient = DependencyManager::get<AssetClient>();
auto request = assetClient->createSetMappingRequest(path, hash);
@ -152,6 +159,8 @@ void AssetMappingModel::refresh() {
bool isFolder = i < length - 1;
item->setData(isFolder ? fullPath + "/" : fullPath, Qt::UserRole);
item->setData(isFolder, Qt::UserRole + 1);
item->setData(parts[i], Qt::UserRole + 2);
item->setData("atp:" + fullPath, Qt::UserRole + 3);
if (lastItem) {
lastItem->setChild(lastItem->rowCount(), 0, item);
} else {

View file

@ -18,6 +18,7 @@
#include <QtScript/QScriptValue>
#include <AssetClient.h>
#include <QSortFilterProxyModel>
class AssetMappingItem : public QStandardItem {
public:
@ -39,6 +40,8 @@
Q_INVOKABLE void refresh();
bool isKnownMapping(QString path) const { return _pathToItemMap.contains(path); };
private:
QHash<QString, QStandardItem*> _pathToItemMap;
};
@ -47,8 +50,14 @@
class AssetMappingsScriptingInterface : public QObject, public Dependency {
Q_OBJECT
Q_PROPERTY(AssetMappingModel* mappingModel READ getAssetMappingModel CONSTANT)
Q_PROPERTY(QAbstractProxyModel* proxyModel READ getProxyModel CONSTANT)
public:
AssetMappingsScriptingInterface();
Q_INVOKABLE AssetMappingModel* getAssetMappingModel() { return &_assetMappingModel; }
Q_INVOKABLE QAbstractProxyModel* getProxyModel() { return &_proxyModel; }
Q_INVOKABLE bool isKnownMapping(QString path) const { return _assetMappingModel.isKnownMapping(path); };
Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback);
Q_INVOKABLE void getMapping(QString path, QJSValue callback);
@ -59,6 +68,7 @@ public:
protected:
QSet<AssetRequest*> _pendingRequests;
AssetMappingModel _assetMappingModel;
QSortFilterProxyModel _proxyModel;
};