Skip to content

Commit

Permalink
Add test for non-writable paths and show message if macos app store.
Browse files Browse the repository at this point in the history
  • Loading branch information
andeplane committed May 12, 2017
1 parent d13c6d4 commit 96238ce
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
21 changes: 15 additions & 6 deletions src/qml/desktop/MainDesktop.qml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Rectangle {

onCurrentIndexChanged: {
root.viewMode = model[currentIndex].mode
if(root.viewMode === "edit") messageOverlay.visible = false
if(root.viewMode === "edit") messageOverlay.hideClickedAtLeastOnce = true
}

Connections {
Expand Down Expand Up @@ -458,13 +458,12 @@ Rectangle {

MessageOverlay {
id: messageOverlay
property bool shouldBeVisible: simulator.states.idle.active || simulator.states.finished.active || simulator.states.crashed.active || simulator.states.reset.active || simulator.welcomeSimulationRunning

property bool shouldBeVisible: simulator.states.idle.active || simulator.states.finished.active || simulator.states.crashed.active || simulator.states.reset.active || welcome || cantWrite
anchors.fill: parent
visible: false

errorMessage: simulator.error
welcome: simulator.states.idle.active || simulator.welcomeSimulationRunning
welcome: (simulator.states.idle.active || simulator.welcomeSimulationRunning) && !hideClickedAtLeastOnce
finished: simulator.states.finished.active
crashed: simulator.states.crashed.active
cancelling: simulator.states.reset.active
Expand All @@ -481,7 +480,6 @@ Rectangle {
}

onExamplesClicked: modeMenu.currentIndex = 3
onHideClicked: visible = false
onShouldBeVisibleChanged: {
if(shouldBeVisible) {
visible = true
Expand Down Expand Up @@ -586,14 +584,25 @@ Rectangle {
id: shortcuts
Shortcut {
sequence: "Return"
onActivated: messageOverlay.visible = false
onActivated: messageOverlay.hideClicked()
}

EventCatcher {
name: "simulator.togglePause"
onTriggered: simulator.togglePause()
}


EventCatcher {
name: "editor.cantwrite"
onTriggered: {
console.log("Mac app store: ", simulator.system.macAppStore)
if(simulator.system.macAppStore) {
messageOverlay.cantWrite = true
}
}
}

EventCatcher {
name: "editor.focus"
onTriggered: editor.editorWindow.currentEditor.textArea.forceActiveFocus()
Expand Down
29 changes: 28 additions & 1 deletion src/qml/desktop/MessageOverlay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,35 @@ Rectangle {
signal newTabClicked()
signal hideClicked()

onHideClicked: {
hideClickedAtLeastOnce = true
cantWrite = false
visible = false
}

Timer {
interval: 1000
repeat: true
running: true
onTriggered: console.log("Welcome now: ", welcome)
}

property bool hideClickedAtLeastOnce: false // TODO: state machinery should be used...
property bool welcome: true
property bool finished: false
property bool crashed: false
property bool cancelling: false
property bool cantWrite: false // TODO: rename to showCantWrite
property string cantWriteMacOSAppStoreText:
"
<style>
h2 { text-align: center; }
a { font-weight: bold; color: #56b1b4; text-decoration: none; }
</style>
<h2>File access problem:</h2>
<p>This simulation is in a directory which Atomify cannot write to. Due to limitations<br>
to file access in the Mac App Store, your simulations must be in the Downloads folder. </p>"

property string cancellingText:
"
<style>
Expand Down Expand Up @@ -72,7 +97,9 @@ Learn more about Atomify at <a href=\"website\">ovilab.net/atomify</a>. We love
textFormat: TextEdit.RichText
wrapMode: TextArea.WordWrap
text: {
if(welcome) {
if(cantWrite) {
return cantWriteMacOSAppStoreText
} else if(welcome) {
return welcomeText
} else if(finished) {
return finishedText
Expand Down
14 changes: 10 additions & 4 deletions src/qml/desktop/editor/CodeEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import QtQuick.Controls 2.1

import QtQuick.Dialogs 1.2
import Atomify 1.0
import "../../events"

Item {
id: root
Expand All @@ -18,6 +19,11 @@ Item {
property int currentLine: -1
property int errorLine: -1

Component.onCompleted: {
highlighter.setTextDocument(textArea.textDocument)
EventCenter.register("editor.cantwrite")
}

onCurrentLineChanged: {
lineNumbers.currentLine = currentLine
textArea.update()
Expand All @@ -44,6 +50,10 @@ Item {
}
loadAndUpdateTextField()
}

if(root.visible && backend.fileExists(fileUrl) && !backend.filePathIsWritable(fileUrl)) {
EventCenter.postEvent("editor.cantwrite", fileName)
}
}

function fileExists(path) {
Expand Down Expand Up @@ -96,10 +106,6 @@ Item {
fileDialogSave.open()
}

Component.onCompleted: {
highlighter.setTextDocument(textArea.textDocument)
}

Highlighter {
id: highlighter
}
Expand Down
4 changes: 4 additions & 0 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ unix:!macx {
QMAKE_CXXFLAGS += -fopenmp
LIBS += -fopenmp
}

macx {
QMAKE_MAC_SDK = macosx10.9
ICON = images/icon.icns
QMAKE_INFO_PLIST = info.plist
}

# DEFINES += MACAPPSTORE

ios {
QMAKE_INFO_PLIST = iOS.plist
}
Expand Down

0 comments on commit 96238ce

Please sign in to comment.