fixed entering path from the addressbar
[case] / src / fileoperator.cpp
index a779a87..1dcdae8 100644 (file)
@@ -106,9 +106,27 @@ FileOperator::FileOperator(QWidget *parent) : QWidget(parent) {
 
 QString FileOperator::shortenPath(const QString &path) {
     QString homePath = QFSFileEngine::homePath();
-    QString result = path;
+
     if (path.indexOf(homePath, 0) == 0) {
+        QString result = path;
+
         result.replace(0, homePath.size(), "~");
+        return result;
+    }
+
+    return path;
+}
+
+
+QString FileOperator::unwindPath(const QString &path) {
+    QString result = path;
+    // if ~ is the first character and / or nothing follows it, replace with home dir
+    if (path == "~" || path.indexOf("~/", 0) == 0) {
+        QString homePath = QFSFileEngine::homePath();
+        result.replace(0, 1, homePath);
+    // in case someone wants to enter a dir called ~ in the current dir, he can escape it with \~
+    } else if (path == "\\~" || path.indexOf("\\~/", 0) == 0) {
+        result.replace(0, 2, "~");
     }
 
     return result;