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 } HifiConstants { id: hifi }
property var scripts: ScriptDiscoveryService; property var scripts: ScriptDiscoveryService;
property var scriptsModel: Assets.mappingModel; property var assetMappingsModel: Assets.proxyModel;
property var currentDirectory; property var currentDirectory;
property alias currentFileUrl: fileUrlTextField.text; property alias currentFileUrl: fileUrlTextField.text;
@ -67,8 +67,8 @@ Window {
}); });
} }
function fileExists(destinationPath) { function fileExists(path) {
return true; // TODO get correct value return Assets.isKnownMapping(path);
} }
function askForOverride(path, callback) { function askForOverride(path, callback) {
@ -89,7 +89,7 @@ Window {
function canAddToWorld() { function canAddToWorld() {
var supportedExtensions = [/\.fbx\b/i, /\.obj\b/i]; 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 supportedExtensions.reduce(function(total, current) {
return total | new RegExp(current).test(path); return total | new RegExp(current).test(path);
@ -98,18 +98,25 @@ Window {
function reload() { function reload() {
print("reload"); print("reload");
scriptsModel.refresh(); Assets.mappingModel.refresh();
} }
function addToWorld() { function addToWorld() {
var path = scriptsModel.data(treeView.currentIndex, 0x100); var path = assetMappingsModel.data(treeView.currentIndex, 0x100);
if (!path) { if (!path) {
return; return;
} }
print("addToWorld");
} }
function copyURLToClipboard() {
var path = assetMappingsModel.data(treeView.currentIndex, 0x103);
if (!path) {
return;
}
Window.copyToClipboard(path);
}
function renameFile() { function renameFile() {
var path = scriptsModel.data(treeView.currentIndex, 0x100); var path = assetMappingsModel.data(treeView.currentIndex, 0x100);
if (!path) { if (!path) {
return; return;
} }
@ -120,6 +127,9 @@ Window {
placeholderText: "Enter path here" placeholderText: "Enter path here"
}); });
object.selected.connect(function(destinationPath) { object.selected.connect(function(destinationPath) {
if (path == destinationPath) {
return;
}
if (fileExists(destinationPath)) { if (fileExists(destinationPath)) {
askForOverride(destinationPath, function() { askForOverride(destinationPath, function() {
doRenameFile(path, destinationPath); doRenameFile(path, destinationPath);
@ -130,17 +140,20 @@ Window {
}); });
} }
function deleteFile() { function deleteFile() {
var path = scriptsModel.data(treeView.currentIndex, 0x100); var path = assetMappingsModel.data(treeView.currentIndex, 0x100);
if (!path) { if (!path) {
return; return;
} }
var isFolder = assetMappingsModel.data(treeView.currentIndex, 0x101);
var typeString = isFolder ? 'folder' : 'file';
var object = desktop.messageBox({ var object = desktop.messageBox({
icon: OriginalDialogs.StandardIcon.Question, icon: OriginalDialogs.StandardIcon.Question,
buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No, buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No,
defaultButton: OriginalDialogs.StandardButton.No, defaultButton: OriginalDialogs.StandardButton.No,
text: "Deleting", text: "Deleting",
informativeText: "You are about to delete the following file:\n" + informativeText: "You are about to delete the following " + typeString + ":\n" +
path + path +
"\nDo you want to continue?" "\nDo you want to continue?"
}); });
@ -166,7 +179,7 @@ Window {
var fileUrl = fileUrlTextField.text var fileUrl = fileUrlTextField.text
var addToWorld = addToWorldCheckBox.checked 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 directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : "";
var filename = fileUrl.slice(fileUrl.lastIndexOf('/') + 1); var filename = fileUrl.slice(fileUrl.lastIndexOf('/') + 1);
@ -211,6 +224,16 @@ Window {
onClicked: root.reload() 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 { HifiControls.Button {
text: "ADD TO WORLD" text: "ADD TO WORLD"
color: hifi.buttons.white color: hifi.buttons.white
@ -249,7 +272,7 @@ Window {
HifiControls.Tree { HifiControls.Tree {
id: treeView id: treeView
height: 400 height: 400
treeModel: scriptsModel treeModel: assetMappingsModel
colorScheme: root.colorScheme colorScheme: root.colorScheme
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right 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 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include <QClipboard>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QMessageBox> #include <QMessageBox>
#include <QScriptValue> #include <QScriptValue>
@ -139,3 +140,8 @@ int WindowScriptingInterface::getX() {
int WindowScriptingInterface::getY() { int WindowScriptingInterface::getY() {
return qApp->getWindow()->y(); 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 prompt(const QString& message = "", const QString& defaultText = "");
QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = ""); QScriptValue browse(const QString& title = "", const QString& directory = "", const QString& nameFilter = "");
QScriptValue save(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: signals:
void domainChanged(const QString& domainHostname); void domainChanged(const QString& domainHostname);

View file

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

View file

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