Skip to content

Commit

Permalink
Automatically restore opened tabs (#126)
Browse files Browse the repository at this point in the history
* automatically restore opened tabs
* restore active tab at startup
* add support for syntax highlighting for .mjs files
  • Loading branch information
milikhin authored Jul 13, 2021
1 parent 0f1ce72 commit f60ea19
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 34 deletions.
6 changes: 5 additions & 1 deletion editor/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ export default class Editor {
// load new content and activate required mode
this._ace.setValue(content)
if (!this._isTerminal) {
const { mode } = modelist.getModeForPath(filePath)
let { mode } = modelist.getModeForPath(filePath)
if (filePath.endsWith('.mjs')) {
mode = 'ace/mode/javascript'
}
editorSession.setMode(mode)
}
this._ace.clearSelection()
Expand All @@ -124,6 +127,7 @@ export default class Editor {

activate () {
this._onChange()
this._ace.resize()
}

deactivate () {
Expand Down
6 changes: 5 additions & 1 deletion editor/src/tabs-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ export default class TabsController {
readOnly = false,
isSailfish = false,
isTerminal = false,
doNotActivate = false,
editorConfig = {}
} = options
const editorElem = document.createElement('div')
editorElem.style.display = 'none'
this._rootElem.appendChild(editorElem)
editorElem.classList.add('editor')

Expand All @@ -59,7 +61,9 @@ export default class TabsController {
tab.editor.onChange(tab.onStateChange)

this._tabs.push(tab)
this.show(filePath)
if (!doNotActivate) {
this.show(filePath)
}
return tab
}

Expand Down
15 changes: 8 additions & 7 deletions generic/qml/EditorApi.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ QtObject {

/**
* Loads file at `filePath` into the editor.
* Creates file if not exists.
* It is possible to create file if not exists.
* @returns {undefined}
*/
function loadFile(filePath, readOnly, callback) {
function loadFile(filePath, readOnly, createIfNotExtist, doNotActivate, callback) {
py.getEditorConfig(filePath, function(err, editorConfig) {
if (err) {
return callback(err)
Expand All @@ -77,6 +77,10 @@ QtObject {
return callback(null, false)
}

if (!createIfNotExtist) {
return callback(err)
}

QmlJs.writeFile(filePath, '', function(err) {
if (err) {
errorOccured(writeErrorMsg.arg(filePath))
Expand All @@ -94,10 +98,10 @@ QtObject {
filePath: filePath,
editorConfig: editorConfig,
readOnly: readOnly,
content: content
content: content,
doNotActivate: doNotActivate
})
}

}

function openFile(filePath) {
Expand Down Expand Up @@ -160,9 +164,6 @@ QtObject {

function startup() {
loadTheme()
if (filePath) {
loadFile(filePath, false, Function.prototype)
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions generic/qml/TabsModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ ListModel {
id: options.id,
hasChanges: false,
isBusy: false,
isInitial: options.isInitial,
isTerminal: options.isTerminal || false,
title: options.title,
subTitle: options.subTitle,
uniqueTitle: options.title,
readOnly: options.isTerminal || options.readOnly || false,
doNotActivate: options.doNotActivate,

filePath: options.filePath
}
Expand Down
2 changes: 1 addition & 1 deletion harbour-seabass/qml/pages/Editor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Page {
if (api.filePath) {
api.closeFile(api.filePath)
}
api.loadFile(selectedContentProperties.filePath, false, Function.prototype)
api.loadFile(selectedContentProperties.filePath, false, true, false, Function.prototype)
api.openFile(selectedContentProperties.filePath)
}
}
Expand Down
3 changes: 2 additions & 1 deletion ubports-seabass/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<body>
<div id="welcome">
<h1>
Seabass2 v1.1
Seabass2 v1.2
</h1>
<h2>
Features:
Expand All @@ -65,6 +65,7 @@ <h2>
New:
</h2>
<ul>
<li>Restore previous session at startup</li>
<li>Automatically install and launch built projects</li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ubports-seabass/manifest.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"content-hub": "content-hub.json"
}
},
"version": "1.1.0",
"version": "1.2.0",
"maintainer": "Mikhael Milikhin <[email protected]>",
"framework" : "ubuntu-sdk-16.04.5"
}
42 changes: 23 additions & 19 deletions ubports-seabass/po/seabass2.mikhael.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: seabass2.mikhael\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-06-12 20:05+0000\n"
"POT-Creation-Date: 2021-07-10 14:17+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -35,32 +35,32 @@ msgstr ""
msgid "Seabass2"
msgstr ""

#: ../qml/Main.qml:68
#: ../qml/Main.qml:88
msgid "Unable to read file. Please ensure that you have read access to the %1"
msgstr ""

#: ../qml/Main.qml:69
#: ../qml/Main.qml:89
msgid ""
"Unable to write the file. Please ensure that you have write access to %1"
msgstr ""

#: ../qml/Main.qml:241
#: ../qml/Main.qml:276
msgid "Creating a project failed. See build output for details"
msgstr ""

#: ../qml/Main.qml:286
#: ../qml/Main.qml:321
msgid "Creating a Libertine container failed. See build output for details"
msgstr ""

#: ../qml/Main.qml:296
#: ../qml/Main.qml:331
msgid "Update failed. See build output for details"
msgstr ""

#: ../qml/Main.qml:312
#: ../qml/Main.qml:347
msgid "Build (%1) failed. See build output for details"
msgstr ""

#: ../qml/Main.qml:322
#: ../qml/Main.qml:357
msgid "Build and run (%1) failed. See build output for details"
msgstr ""

Expand Down Expand Up @@ -163,58 +163,62 @@ msgstr ""
msgid "Font size, CSS px:"
msgstr ""

#: ../qml/Settings.qml:137
#: ../qml/Settings.qml:131
msgid "Restore previous session at startup:"
msgstr ""

#: ../qml/Settings.qml:157
msgid "Build container"
msgstr ""

#: ../qml/Settings.qml:154
#: ../qml/Settings.qml:174
msgid "You can use the Seabass to build projects with Clickable."
msgstr ""

#: ../qml/Settings.qml:162
#: ../qml/Settings.qml:182
msgid ""
"In order to execute Clickable, Seabass requires a special Libertine "
"container to be created first. Once the container is created you can update "
"it here and manage it as usual using `libertine-container-manager` "
"(container ID is `seabass2-build`) or via the System Settings."
msgstr ""

#: ../qml/Settings.qml:172
#: ../qml/Settings.qml:192
msgid ""
"Should anything goes wrong with the container you can delete and recreate it "
"once again."
msgstr ""

#: ../qml/Settings.qml:193
#: ../qml/Settings.qml:213
msgid "Notes:"
msgstr ""

#: ../qml/Settings.qml:203
#: ../qml/Settings.qml:223
msgid ""
"• To build a project you need to open a corresponding clickable.json file "
"and click the 'Build' button:"
msgstr ""

#: ../qml/Settings.qml:220
#: ../qml/Settings.qml:240
msgid ""
"• Project files should be located inside ~/Downloads or ~/Documents "
"directories. These directories are automatically mounted into Libertine "
"containers. Alternatively you can create additional bind mounts manually."
msgstr ""

#: ../qml/Settings.qml:230
#: ../qml/Settings.qml:250
msgid "• clickable.json file should be named 'clickable.json'."
msgstr ""

#: ../qml/Settings.qml:246
#: ../qml/Settings.qml:266
msgid "Container status:"
msgstr ""

#: ../qml/Settings.qml:268
#: ../qml/Settings.qml:288
msgid "Create build container"
msgstr ""

#: ../qml/Settings.qml:277
#: ../qml/Settings.qml:297
msgid "Update build container"
msgstr ""

Expand Down
39 changes: 37 additions & 2 deletions ubports-seabass/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,27 @@ ApplicationWindow {
readonly property bool isWide: width >= Suru.units.gu(100)
readonly property string defaultTitle: i18n.tr("Welcome")
readonly property string defaultSubTitle: i18n.tr("Seabass2")
readonly property string version: "1.1.0"
readonly property string version: "1.2.0"
property bool hasBuildContainer: false
property int activeTheme: parseInt(settings.theme)

onClosing: {
var files = []
for (var i = 0; i < tabsModel.count; i++) {
var tab = tabsModel.get(i)
if (tab.isTerminal) {
continue
}

files.push(tab.filePath)
if (i === tabBar.currentIndex) {
settings.initialTab = files.length - 1
}
}

settings.initialFiles = files
}

function handleBuilderStarted() {
if (!isWide) {
navBar.visible = false
Expand All @@ -46,6 +63,9 @@ ApplicationWindow {
property bool isKeyboardExtensionVisible: true
property string theme: Constants.Theme.System
property int fontSize: 12
property var initialFiles: []
property int initialTab: 0
property bool restoreOpenedTabs: true
}

GenericComponents.EditorApi {
Expand All @@ -72,6 +92,21 @@ ApplicationWindow {
onErrorOccured: function(message) {
errorDialog.show(message)
}
onAppLoaded: {
if (settings.restoreOpenedTabs) {
for (var i = 0; i < settings.initialFiles.length; i++) {
var filePath = settings.initialFiles[i]
tabsModel.open({
id: filePath,
filePath: filePath,
subTitle: QmlJs.getPrintableDirPath(QmlJs.getDirPath(filePath), api.homeDir),
title: QmlJs.getFileName(filePath),
isInitial: true,
doNotActivate: settings.initialTab !== i
})
}
}
}
onMessageSent: function(jsonPayload) {
editor.runJavaScript("window.postSeabassApiMessage(" + jsonPayload + ")");
}
Expand Down Expand Up @@ -113,7 +148,7 @@ ApplicationWindow {
isTerminal: true
})
}
api.loadFile(tab.filePath, false, function(err, isNewFile) {
api.loadFile(tab.filePath, false, !tab.isInitial, tab.doNotActivate, function(err, isNewFile) {
if (err) {
tabsModel.close(tab.filePath)
}
Expand Down
20 changes: 20 additions & 0 deletions ubports-seabass/qml/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ Item {
}
}

Row {
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Suru.units.gu(1)
anchors.rightMargin: Suru.units.gu(1)
spacing: Suru.units.gu(1)

Label {
anchors.verticalCenter: parent.verticalCenter
text: i18n.tr("Restore previous session at startup:")
}

Switch {
checked: settings.restoreOpenedTabs
onCheckedChanged: {
settings.restoreOpenedTabs = checked
}
}
}

Rectangle {
width: parent.width
height: Suru.units.dp(1)
Expand Down
5 changes: 4 additions & 1 deletion ubports-seabass/qml/components/TabBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ Item {
model: root.model

onItemAdded: function(index) {
tabBar.currentIndex = index
var tab = model.get(index)
if (!tab.doNotActivate) {
tabBar.currentIndex = index
}
}

TabComponents.TabButton {
Expand Down

0 comments on commit f60ea19

Please sign in to comment.