-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from milikhin/harbour-file-list
[sailfish] add ability to create new files
- Loading branch information
Showing
22 changed files
with
548 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import QtQuick 2.0 | ||
import io.thp.pyotherside 1.4 | ||
|
||
import "./utils.js" as QmlJs | ||
|
||
Item { | ||
property string rootDirectory | ||
property string directory | ||
property string prevDirectory | ||
property bool showDotDot: false | ||
property var expanded: [] | ||
property var prevExpanded: [] | ||
|
||
signal errorOccured(string error) | ||
|
||
readonly property var model: ListModel { | ||
Component.onCompleted: { | ||
directoryChanged.connect(reload) | ||
showDotDotChanged.connect(reload) | ||
py.readyChanged.connect(function() { | ||
load(true) | ||
}) | ||
} | ||
} | ||
|
||
readonly property var py: Python { | ||
property bool ready: false | ||
onReceived: function(evtArgs) { | ||
if (evtArgs[0] !== 'fs_event') { | ||
return | ||
} | ||
|
||
load() | ||
} | ||
|
||
Component.onCompleted: { | ||
addImportPath(Qt.resolvedUrl('../py-backend')) | ||
importModule('fs_utils', function() { | ||
ready = true | ||
}) | ||
} | ||
|
||
function listDir(path, expanded, callback) { | ||
const directories = [path].concat(expanded) | ||
py.call('fs_utils.list_files', [directories], function(res) { | ||
callback(res.error, res.result) | ||
}) | ||
py.call('fs_utils.watch_changes', [directories]) | ||
} | ||
} | ||
|
||
function load(ignoreError) { | ||
if (!py.ready) { | ||
return | ||
} | ||
|
||
py.listDir(directory, expanded, function(error, entries) { | ||
if (error) { | ||
directory = prevDirectory | ||
// copy prevExpanded values | ||
expanded = [].concat(prevExpanded) | ||
if (ignoreError) { | ||
return; | ||
} | ||
return errorOccured(error) | ||
} | ||
|
||
const hasDotDot = showDotDot && directory !== rootDirectory | ||
if (hasDotDot) { | ||
model.set(0, { | ||
name: '..', | ||
path: QmlJs.getDirPath(QmlJs.getNormalPath(directory)), | ||
isDir: true | ||
}) | ||
} | ||
|
||
const startIndex = hasDotDot ? 1 : 0 | ||
const totalEntriesNumber = entries.length + startIndex | ||
entries.forEach(function (fileEntry, i) { | ||
var index = startIndex + i | ||
fileEntry.isExpanded = expanded.indexOf(fileEntry.path) !== -1 | ||
if (index < model.count) { | ||
// update non-last model entries | ||
model.set(index, fileEntry) | ||
} else { | ||
// append new model entries | ||
model.append(fileEntry) | ||
} | ||
}) | ||
|
||
if (totalEntriesNumber < model.count) { | ||
model.remove(totalEntriesNumber, model.count - totalEntriesNumber) | ||
} | ||
|
||
prevDirectory = directory | ||
// copy expanded values | ||
prevExpanded = [].concat(expanded) | ||
}) | ||
} | ||
|
||
function reload() { | ||
expanded = [] | ||
load() | ||
} | ||
|
||
function rm(path, callback) { | ||
if (!py.ready) { | ||
return | ||
} | ||
|
||
py.call('fs_utils.rm', [path], function(res) { | ||
callback(res.error) | ||
}) | ||
} | ||
|
||
function rename(originalPath, newPath, callback) { | ||
if (!py.ready) { | ||
return | ||
} | ||
|
||
py.call('fs_utils.rename', [originalPath, newPath], function(res) { | ||
callback(res.error) | ||
}) | ||
} | ||
|
||
function toggleExpanded(path) { | ||
if (expanded.indexOf(path) === -1) { | ||
expanded.push(path) | ||
} else { | ||
var newExpanded = [] | ||
expanded.forEach(function(expandedPath) { | ||
if (expandedPath.indexOf(path) !== 0) { | ||
newExpanded.push(expandedPath) | ||
} | ||
}) | ||
expanded = newExpanded | ||
} | ||
|
||
load() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import QtQuick 2.2 | ||
import Sailfish.Silica 1.0 | ||
|
||
import '../generic/utils.js' as QmlJs | ||
|
||
Rectangle { | ||
id: root | ||
property bool isDarkTheme | ||
property bool highlighed: false | ||
property alias icon: button.icon | ||
signal clicked() | ||
|
||
width: childrenRect.width | ||
height: childrenRect.height | ||
color: isDarkTheme | ||
? QmlJs.colors.DARK_TOOLBAR_BACKGROUND | ||
: QmlJs.colors.LIGHT_TOOLBAR_BACKGROUND | ||
radius: Theme.dp(2) | ||
|
||
Button { | ||
id: button | ||
backgroundColor: Theme.rgba(Theme.highlightBackgroundColor, | ||
highlighed ? Theme.highlightBackgroundOpacity : 0) | ||
border.color: Theme.highlightBackgroundColor | ||
icon.color: highlighed ? Theme.highlightColor : Theme.primaryColor | ||
onClicked: root.clicked() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.