mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 02:43:32 +02:00
Merge pull request #98 from Atlante45/feat/atp
Don't overwrite directories
This commit is contained in:
commit
d52c904070
3 changed files with 29 additions and 8 deletions
|
@ -72,12 +72,16 @@ Window {
|
||||||
|
|
||||||
}
|
}
|
||||||
function doRenameFile(oldPath, newPath) {
|
function doRenameFile(oldPath, newPath) {
|
||||||
console.log("Renaming " + oldPath + " to " + newPath);
|
|
||||||
|
|
||||||
if (newPath[0] != "/") {
|
if (newPath[0] != "/") {
|
||||||
newPath = "/" + newPath;
|
newPath = "/" + newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Assets.isKnownFolder(newPath)) {
|
||||||
|
box = errorMessageBox("Cannot overwrite existing directory.");
|
||||||
|
box.selected.connect(reload);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Renaming " + oldPath + " to " + newPath);
|
||||||
Assets.renameMapping(oldPath, newPath, function(err) {
|
Assets.renameMapping(oldPath, newPath, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("Error renaming: ", oldPath, "=>", newPath, " - error ", err);
|
console.log("Error renaming: ", oldPath, "=>", newPath, " - error ", err);
|
||||||
|
@ -110,9 +114,8 @@ Window {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function canAddToWorld() {
|
function canAddToWorld(path) {
|
||||||
var supportedExtensions = [/\.fbx\b/i, /\.obj\b/i];
|
var supportedExtensions = [/\.fbx\b/i, /\.obj\b/i];
|
||||||
var path = assetProxyModel.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);
|
||||||
|
@ -133,7 +136,7 @@ Window {
|
||||||
|
|
||||||
function addToWorld() {
|
function addToWorld() {
|
||||||
var url = assetProxyModel.data(treeView.currentIndex, 0x103);
|
var url = assetProxyModel.data(treeView.currentIndex, 0x103);
|
||||||
if (!url) {
|
if (!url || !canAddToWorld(url)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(MyAvatar.orientation)));
|
var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(MyAvatar.orientation)));
|
||||||
|
@ -284,7 +287,7 @@ Window {
|
||||||
height: 26
|
height: 26
|
||||||
width: 120
|
width: 120
|
||||||
|
|
||||||
enabled: canAddToWorld()
|
enabled: canAddToWorld(assetProxyModel.data(treeView.currentIndex, 0x100))
|
||||||
|
|
||||||
onClicked: root.addToWorld()
|
onClicked: root.addToWorld()
|
||||||
}
|
}
|
||||||
|
@ -404,6 +407,9 @@ Window {
|
||||||
anchors.rightMargin: uploadButton.width + hifi.dimensions.contentSpacing.x
|
anchors.rightMargin: uploadButton.width + hifi.dimensions.contentSpacing.x
|
||||||
|
|
||||||
text: "Add to world on upload"
|
text: "Add to world on upload"
|
||||||
|
|
||||||
|
opacity: canAddToWorld(fileUrlTextField.text) ? 1 : 0
|
||||||
|
|
||||||
checked: false
|
checked: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,19 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new
|
||||||
request->start();
|
request->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AssetMappingModel::isKnownFolder(QString path) const {
|
||||||
|
if (!path.endsWith("/")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto existingPaths = _pathToItemMap.keys();
|
||||||
|
for (auto& entry : existingPaths) {
|
||||||
|
if (entry.startsWith(path)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
AssetMappingItem::AssetMappingItem(const QString& name, const QString& fullPath, bool isFolder) :
|
AssetMappingItem::AssetMappingItem(const QString& name, const QString& fullPath, bool isFolder) :
|
||||||
name(name),
|
name(name),
|
||||||
|
|
|
@ -35,7 +35,8 @@
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE void refresh();
|
Q_INVOKABLE void refresh();
|
||||||
|
|
||||||
bool isKnownMapping(QString path) const { return _pathToItemMap.contains(path); };
|
bool isKnownMapping(QString path) const { return _pathToItemMap.contains(path); }
|
||||||
|
bool isKnownFolder(QString path) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void errorGettingMappings(int error);
|
void errorGettingMappings(int error);
|
||||||
|
@ -55,7 +56,8 @@ public:
|
||||||
Q_INVOKABLE AssetMappingModel* getAssetMappingModel() { return &_assetMappingModel; }
|
Q_INVOKABLE AssetMappingModel* getAssetMappingModel() { return &_assetMappingModel; }
|
||||||
Q_INVOKABLE QAbstractProxyModel* getProxyModel() { return &_proxyModel; }
|
Q_INVOKABLE QAbstractProxyModel* getProxyModel() { return &_proxyModel; }
|
||||||
|
|
||||||
Q_INVOKABLE bool isKnownMapping(QString path) const { return _assetMappingModel.isKnownMapping(path); };
|
Q_INVOKABLE bool isKnownMapping(QString path) const { return _assetMappingModel.isKnownMapping(path); }
|
||||||
|
Q_INVOKABLE bool isKnownFolder(QString path) const { return _assetMappingModel.isKnownFolder(path); }
|
||||||
|
|
||||||
Q_INVOKABLE QString getErrorString(int errorCode) const;
|
Q_INVOKABLE QString getErrorString(int errorCode) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue