Skip to content

Commit 97f1a7f

Browse files
authored
Merge pull request #157 from milikhin/harbour-settings
Add Settings page to harbour-seabass
2 parents 3d37ff3 + ad7d28f commit 97f1a7f

20 files changed

+960
-1718
lines changed

editor/__tests__/app/app.test.js

-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,5 @@ describe('SeabassApp', () => {
1919
// Check for 'appLoaded' action
2020
const evt = await waitForApiMessage
2121
expect(evt.detail.action).toEqual('appLoaded')
22-
expect(evt.detail.data).toEqual({
23-
isToolbarOpened: true,
24-
directory: null
25-
})
2622
})
2723
})

editor/__tests__/app/model.test.js

-15
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ describe('SeabassAppModel', () => {
1818
expect(model._viewport).toEqual({
1919
verticalHtmlOffset: 0
2020
})
21-
expect(model.sailfishPreferences).toEqual({
22-
isToolbarOpened: true,
23-
directory: null
24-
})
2521
})
2622
})
2723

@@ -204,15 +200,4 @@ describe('SeabassAppModel', () => {
204200
})
205201
})
206202
})
207-
208-
describe('#setSailfishPreferences', () => {
209-
it('should set toolbar visibility', () => {
210-
const model = new SeabassAppModel()
211-
212-
const options = { isToolbarOpened: true }
213-
model.setSailfishPreferences(options)
214-
215-
expect(model._sailfish.isToolbarOpened).toEqual(options.isToolbarOpened)
216-
})
217-
})
218203
})

editor/src/api/api-interface.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InputPreferences, SeabassSailfishPreferences, ViewportOptions } from '../app/model'
1+
import { InputPreferences, ViewportOptions } from '../app/model'
22
import { KeyDownOptions } from '../editor/editor'
33

44
export interface ApiTransport {
@@ -56,7 +56,6 @@ export interface IncomingMessagePayload {
5656
requestSaveAndClose: FileActionOptions
5757
setContent: SetContentOptions
5858
setPreferences: InputPreferences
59-
setSailfishPreferences: SeabassSailfishPreferences
6059
undo: undefined
6160
toggleReadOnly: undefined
6261
}

editor/src/api/api.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SocketApiTransport from './socket-transport'
1010
/** Outgoing API message to a platform-specific app */
1111
interface OutgoingApiMessage {
1212
action: string
13-
data: unknown
13+
data?: unknown
1414
}
1515

1616
interface ApiOptions {
@@ -45,7 +45,6 @@ export default class SeabassApi extends EventTarget {
4545
'requestSaveAndClose',
4646
'setContent',
4747
'setPreferences',
48-
'setSailfishPreferences',
4948
'toggleReadOnly',
5049
'undo',
5150
'viewportChange'

editor/src/app/app.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import SeabassView from './view'
99
import SeabassAppModel, {
1010
EditorStateChangeOptions,
1111
InputPreferences,
12-
SeabassSailfishPreferences,
1312
ViewportOptions
1413
} from './model'
1514

@@ -46,7 +45,7 @@ class SeabassApp {
4645
this._tabs = new Tabs({ rootElem })
4746

4847
this._registerApiEventListeners()
49-
this._api.send({ action: 'appLoaded', data: this._model.sailfishPreferences })
48+
this._api.send({ action: 'appLoaded' })
5049
}
5150

5251
/**
@@ -64,7 +63,6 @@ class SeabassApp {
6463
this._api.addEventListener('requestSaveAndClose', this._onRequestFileSave.bind(this))
6564
this._api.addEventListener('setContent', this._forwardEvent.bind(this))
6665
this._api.addEventListener('setPreferences', this._onSetPreferences.bind(this))
67-
this._api.addEventListener('setSailfishPreferences', this._onSetSailfishPreferences.bind(this))
6866
this._api.addEventListener('toggleReadOnly', this._forwardEvent.bind(this))
6967
this._api.addEventListener('undo', this._forwardEvent.bind(this))
7068
this._api.addEventListener('viewportChange', this._onViewportChange.bind(this))
@@ -118,8 +116,8 @@ class SeabassApp {
118116
}
119117

120118
/**
121-
* Loads saved SailfishOS-specific preferences
122-
* @param evt setTheme event
119+
* Handles viewport changes
120+
* @param evt viewportChange event
123121
*/
124122
_onViewportChange (evt: CustomEvent<ViewportOptions>): void {
125123
this._model.setViewportOptions(evt.detail)
@@ -146,14 +144,6 @@ class SeabassApp {
146144
this._model.setPreferences(evt.detail)
147145
}
148146

149-
/**
150-
* Loads saved SailfishOS-specific preferences
151-
* @param evt setTheme event
152-
*/
153-
_onSetSailfishPreferences (evt: CustomEvent<SeabassSailfishPreferences>): void {
154-
this._model.setSailfishPreferences(evt.detail)
155-
}
156-
157147
/**
158148
* Forwards UI state changes to the platform-specific app
159149
* @param evt state change event

editor/src/app/model.ts

-42
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ export interface SeabassCommonPreferences {
2626
useWrapMode?: boolean
2727
}
2828

29-
export interface SeabassSailfishPreferences {
30-
/** Bottom toolbar state */
31-
isToolbarOpened: boolean
32-
/** Current file tree directory */
33-
directory: string|null
34-
}
35-
3629
export interface ViewportOptions {
3730
/** HTML page's offset from the bottom of webView. Used as a workaround to SfOS rendering issues */
3831
verticalHtmlOffset: number
@@ -47,7 +40,6 @@ interface AppEvents {
4740
loadFile: CustomEvent<FileLoadOptions>
4841
log: CustomEvent<unknown>
4942
preferencesChange: CustomEvent<SeabassCommonPreferences>
50-
sfosPreferencesChange: CustomEvent<SeabassSailfishPreferences>
5143
stateChange: CustomEvent<EditorStateChangeOptions>
5244
}
5345

@@ -72,36 +64,19 @@ export default class SeabassAppModel extends EventTarget {
7264
useWrapMode: boolean
7365
}
7466

75-
/** SailfishOS-specific preferences */
76-
_sailfish: {
77-
isToolbarOpened: boolean
78-
directory: string|null
79-
}
80-
8167
_viewport: {
8268
verticalHtmlOffset: number
8369
}
8470

85-
SFOS_TOOLBAR_LOCAL_STORAGE_KEY = 'sailfish__isToolbarOpened'
86-
SFOS_DIRECTORY_LOCAL_STORAGE_KEY = 'sailfish__directory'
87-
8871
constructor () {
8972
super()
9073
this._editors = new Map()
9174
this._preferences = { isDarkTheme: false, useWrapMode: true }
92-
this._sailfish = {
93-
isToolbarOpened: localStorage.getItem(this.SFOS_TOOLBAR_LOCAL_STORAGE_KEY) === 'true',
94-
directory: localStorage.getItem(this.SFOS_DIRECTORY_LOCAL_STORAGE_KEY)
95-
}
9675
this._viewport = {
9776
verticalHtmlOffset: 0
9877
}
9978
}
10079

101-
get sailfishPreferences (): SeabassSailfishPreferences {
102-
return this._sailfish
103-
}
104-
10580
addEventListener<T extends keyof AppEvents>(type: T,
10681
callback: AppEventListener<T>, options?: EventListenerOptions): void {
10782
super.addEventListener(type, callback as EventListenerOrEventListenerObject | null, options)
@@ -213,21 +188,4 @@ export default class SeabassAppModel extends EventTarget {
213188
this.dispatchEvent(new CustomEvent('htmlThemeChange', { detail: this._htmlTheme }))
214189
this.dispatchEvent(new CustomEvent('preferencesChange', { detail: this._preferences }))
215190
}
216-
217-
/**
218-
* Sets sailfish-specific app preferences
219-
* @param options app preferences
220-
*/
221-
setSailfishPreferences (options: Partial<SeabassSailfishPreferences>): void {
222-
if (options.isToolbarOpened !== undefined) {
223-
this._sailfish.isToolbarOpened = options.isToolbarOpened
224-
localStorage.setItem(this.SFOS_TOOLBAR_LOCAL_STORAGE_KEY, options.isToolbarOpened.toString())
225-
}
226-
if (options.directory !== undefined && options.directory !== null) {
227-
this._sailfish.directory = options.directory
228-
localStorage.setItem(this.SFOS_DIRECTORY_LOCAL_STORAGE_KEY, options.directory)
229-
}
230-
231-
this.dispatchEvent(new CustomEvent('sfosPreferencesChange', { detail: this._sailfish }))
232-
}
233191
}

editor/src/editor/editor.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ export default class Editor extends EventTarget {
9393
* Destroys editor
9494
*/
9595
destroy (): void {
96+
this._removeDomEventHandlers()
97+
this._editor.destroy()
9698
const editorParentElem = this._editorElem.parentElement as HTMLElement
9799
editorParentElem.removeChild(this._editorElem)
98-
this._removeDomEventHandlers()
99100
}
100101

101102
dispatchEvent<T extends keyof Events> (event: Events[T]): boolean {

harbour-seabass/harbour-seabass.pro

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ DISTFILES += qml/harbour-seabass.qml \
3030
qml/pages/Files.qml \
3131
qml/pages/NewFile.qml \
3232
qml/pages/SaveDialog.qml \
33+
qml/pages/Settings.qml \
3334
qml/py-backend \
3435
rpm/harbour-seabass.changes.in \
3536
rpm/harbour-seabass.changes.run.in \

harbour-seabass/html/index.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
</style>
99
<style id="theme-css">
10-
/* CSS Custom Properties are not supported in Sailfish */
10+
/* CSS Custom Properties were not supported in Sailfish prior to v4.2 */
1111
/* these values are going to be replaces within JS: */
1212
body {
1313
/*background-color: #backgroungColor */
@@ -18,15 +18,17 @@
1818
#welcome a {
1919
/* color: #highlightColor */
2020
}
21+
.cm-editor {
22+
/* font-size: #fontSize */
23+
}
2124
</style>
2225
</head>
2326

2427
<body>
2528
<div id="welcome">
2629
<p>
27-
v0.10 introduces new file picker component.
28-
It has compact design, remembers last opened directory and provides possiblity
29-
to create new files.
30+
v0.11 introduces Settings page.
31+
It is possible to change font size and text wrapping.
3032
</p>
3133
<p>
3234
Please let me know if you have any issues:

harbour-seabass/qml/pages/About.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Page {
99
anchors.fill: parent
1010
header: PageHeader {
1111
id: header
12-
title: qsTr('Seabass v%1').arg('0.10.0')
12+
title: qsTr('Seabass v%1').arg('0.11.0')
1313
}
1414
model: ListModel {
1515
ListElement {

harbour-seabass/qml/pages/Editor.qml

+58-18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Sailfish.Silica 1.0
44
import Sailfish.Pickers 1.0
55
import Sailfish.WebView 1.0
66
import Sailfish.WebEngine 1.0
7+
import Nemo.Configuration 1.0
78

89
import '../generic/utils.js' as QmlJs
910
import '../components' as PlatformComponents
@@ -31,20 +32,43 @@ WebViewPage {
3132
width: page.width
3233
}
3334

35+
Component.onCompleted: {
36+
pageStack.busyChanged.connect(function() {
37+
if (!hasOpenedFile) {
38+
return
39+
}
40+
41+
if (!pageStack.busy) {
42+
page.isMenuEnabled = false
43+
}
44+
})
45+
}
46+
47+
ConfigurationValue {
48+
id: configToolbarVisibility
49+
key: "/apps/harbour-seabass/settings/is_toolbar_visible"
50+
defaultValue: false
51+
}
52+
53+
ConfigurationValue {
54+
id: configFontSize
55+
key: "/apps/harbour-seabass/settings/font_size"
56+
defaultValue: 12
57+
}
58+
59+
ConfigurationValue {
60+
id: configUseWrapMode
61+
key: "/apps/harbour-seabass/settings/soft_wrap_enabled"
62+
defaultValue: true
63+
}
64+
3465
GenericComponents.EditorState {
3566
id: editorState
3667
isDarkTheme: Theme.colorScheme === Theme.LightOnDark
68+
directory: api.homeDir
69+
fontSize: configFontSize.value
70+
useWrapMode: configUseWrapMode.value
3771
verticalHtmlOffset: headerHeight / WebEngineSettings.pixelRatio
38-
39-
onFilePathChanged: {
40-
isMenuEnabled = false
41-
}
42-
43-
onDirectoryChanged: {
44-
api.postMessage('setSailfishPreferences', {
45-
directory: directory
46-
})
47-
}
4872
}
4973

5074
GenericComponents.EditorApi {
@@ -57,9 +81,6 @@ WebViewPage {
5781

5882
// API methods
5983
onAppLoaded: function (data) {
60-
toolbar.open = data.isToolbarOpened || false
61-
// use `data.directory || api.homeDir` to restore last opened directory when opening app
62-
editorState.directory = api.homeDir
6384
editorState.loadTheme()
6485
editorState.updateViewport()
6586
}
@@ -87,7 +108,7 @@ WebViewPage {
87108
page: page
88109
title: hasOpenedFile
89110
? ((editorState.hasChanges ? '*' : '') + QmlJs.getFileName(filePath))
90-
: qsTr('Seabass v%1').arg('0.10.0')
111+
: qsTr('Seabass v%1').arg('0.11.0')
91112
description: hasOpenedFile
92113
? QmlJs.getPrintableDirPath(QmlJs.getDirPath(filePath), api.homeDir)
93114
: qsTr('Release notes')
@@ -169,6 +190,12 @@ WebViewPage {
169190
toolbar.open = !toolbar.open
170191
}
171192
}
193+
MenuItem {
194+
text: qsTr('Settings')
195+
onClicked: {
196+
pageStack.push(settings)
197+
}
198+
}
172199
MenuItem {
173200
text: qsTr('About')
174201
onClicked: {
@@ -183,7 +210,7 @@ WebViewPage {
183210
width: parent.width
184211
height: Theme.itemSizeMedium
185212
focus: false
186-
open: false
213+
open: configToolbarVisibility.value
187214
background: Rectangle {
188215
// default background doesn't look good when virtual keyboard is opened
189216
// hence the workaround with Rectangle
@@ -193,9 +220,7 @@ WebViewPage {
193220
}
194221

195222
onOpenChanged: {
196-
api.postMessage('setSailfishPreferences', {
197-
isToolbarOpened: open
198-
})
223+
configToolbarVisibility.value = open
199224
}
200225

201226
PlatformComponents.Toolbar {
@@ -290,6 +315,21 @@ WebViewPage {
290315
}
291316
}
292317

318+
Component {
319+
id: settings
320+
Settings {
321+
fontSize: configFontSize.value
322+
useWrapMode: configUseWrapMode.value
323+
324+
onFontSizeChanged: {
325+
configFontSize.value = fontSize
326+
}
327+
onUseWrapModeChanged: {
328+
configUseWrapMode.value = useWrapMode
329+
}
330+
}
331+
}
332+
293333
/**
294334
* Displays error message
295335
* @param {string} [errorMessage] - error message to display

0 commit comments

Comments
 (0)