aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/SaveBar.qml
blob: aa64868c2f36812eeebfaa3f2c05a9b032396cb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

import QtQuick

// Save and Discard for a settings page that edits a draft: its fields change
// the draft, and nothing reaches the file until Save. Sits in the Page header
// through Page.actions. note says what is wrong when Save is held back.
Row {
    id: bar
    property bool dirty: false
    property bool valid: true
    property string note: ""
    signal save
    signal discard
    spacing: 8

    Text {
        anchors.verticalCenter: parent.verticalCenter
        visible: bar.dirty
        text: !bar.valid ? (bar.note || "fix the fields marked red") : "unsaved changes"
        color: bar.valid ? Theme.yellow : Theme.red
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
    }
    Button {
        text: "Discard"
        enabled: bar.dirty
        onClicked: bar.discard()
    }
    Button {
        text: "Save"
        enabled: bar.dirty && bar.valid
        onClicked: bar.save()
    }
}