Skip to content

Commit

Permalink
[harbour-seabass] fix regressions in error handling, navigating and s…
Browse files Browse the repository at this point in the history
…witching themes
  • Loading branch information
milikhin committed May 16, 2020
1 parent 872267f commit e1fff91
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 42 deletions.
2 changes: 1 addition & 1 deletion harbour-seabass/qml/components/Toolbar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Item {
IconButton {
icon.source: "image://theme/icon-m-right"
onClicked: root.navigateRight()
onPressAndHold: root.navigateFileEnd()
onPressAndHold: root.navigateLineEnd()
}

IconButton {
Expand Down
18 changes: 9 additions & 9 deletions harbour-seabass/qml/generic/EditorApi.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ QtObject {
signal errorOccured(string message)

Component.onCompleted: {
isAppLoadedChanged.connect(startup)
filePathChanged.connect(openFile)
isDarkThemeChanged.connect(switchTheme)
appLoaded.connect(startup)
filePathChanged.connect(loadFile)
isDarkThemeChanged.connect(loadTheme)
}

/**
* Opens file at `filePath` in the editor
* @returns {undefined}
*/
function openFile() {
function loadFile() {
QmlJs.readFile(filePath, function(err, text) {
if (err) {
console.error(err)
Expand Down Expand Up @@ -64,22 +64,22 @@ QtObject {
return QmlJs.writeFile(filePath, content, function(err) {
isSaveInProgress = false
if (err) {
return displayError(err,
qsTr('Unable to write the file. Please ensure that you have write access to') + ' ' + filePath)
console.error(err)
return errorOccured(qsTr('Unable to write the file. Please ensure that you have write access to') + ' ' + filePath)
}
})
}

function switchTheme() {
function loadTheme() {
postMessage('setPreferences', {
isDarkTheme: isDarkTheme
})
}

function startup() {
switchTheme()
loadTheme()
if (filePath) {
openFile()
loadFile()
}
}

Expand Down
49 changes: 17 additions & 32 deletions harbour-seabass/qml/pages/Editor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,35 @@ import '../generic' as GenericComponents

Page {
id: page
property bool isDarkTheme: Theme.colorScheme === Theme.LightOnDark
property bool isAppLoaded: false
property string seabassFilePath

allowedOrientations: Orientation.All

GenericComponents.EditorApi {
id: api
filePath: seabassFilePath
isReadOnly: filePath === QmlJs.DEFAULT_FILE_PATH
forceReadOnly: filePath === QmlJs.DEFAULT_FILE_PATH
isDarkTheme: Theme.colorScheme === Theme.LightOnDark
isReadOnly: filePath === QmlJs.DEFAULT_FILE_PATH

onMessageSent: function(jsonMessage) {
webView.experimental.postMessage(jsonMessage)
onAppLoaded: function (data) {
toolbar.open = data.isSailfishToolbarOpened || false
}
onErrorOccured: function (message) {
displayError(message)
}

onIsReadOnlyChanged: {
if (isReadOnly) {
Qt.inputMethod.hide()
}
}

onAppLoaded: function (data) {
isAppLoaded = true
console.log(JSON.stringify(data))
toolbar.open = data.isSailfishToolbarOpened
}
}

onIsDarkThemeChanged: {
if (!isAppLoaded) {
return
onMessageSent: function(jsonMessage) {
webView.experimental.postMessage(jsonMessage)
}

api.isDarkTheme = isDarkTheme
}

onOrientationChanged: fixResize()

// #region LAYOUT

SilicaWebView {
id: webView
url: '../html/index.html'
Expand Down Expand Up @@ -82,12 +70,7 @@ Page {
PushUpMenu {
MenuItem {
text: qsTr(toolbar.open ? "Hide toolbar" : "Show toolbar")
onClicked: {
toolbar.open = !toolbar.open
api.postMessage('setPreferences', {
isSailfishToolbarOpened: toolbar.open
})
}
onClicked: toolbar.open = !toolbar.open
}
MenuItem {
text: qsTr('About')
Expand All @@ -102,6 +85,12 @@ Page {
width: parent.width
height: Theme.itemSizeMedium
focus: false
open: false
onOpenChanged: {
api.postMessage('setPreferences', {
isSailfishToolbarOpened: open
})
}

PlatformComponents.Toolbar {
hasUndo: api.hasUndo
Expand Down Expand Up @@ -138,12 +127,10 @@ Page {

/**
* Displays error message
* @param {Error} error - error object
* @param {string} [errorMessage] - error message to display
* @returns {undefined}
*/
function displayError(error, errorMessage) {
console.error(error, errorMessage)
function displayError(errorMessage) {
pageStack.completeAnimation()
pageStack.push(Qt.resolvedUrl("ErrorDialog.qml"), {
"text": errorMessage || error.message
Expand All @@ -170,6 +157,4 @@ Page {
page.x = 1
page.x = 0
}

// #endregion JS_FUNCTIONS
}

0 comments on commit e1fff91

Please sign in to comment.