Integrated file selection dialogue with the main code. Improved the
[openvpnui.git] / qml / filebrowse / pages / RenameDialog.qml
1 import QtQuick 2.0
2 import Sailfish.Silica 1.0
3 import "functions.js" as Functions
4 import "../components"
5
6 Dialog {
7     property string path: ""
8
9     // return values
10     property string errorMessage: ""
11     property string newPath: ""
12
13     id: dialog
14     allowedOrientations: Orientation.All
15     canAccept: newName.text !== ""
16
17     onAccepted: {
18         var res = engine.rename(path, newName.text);
19         newPath = res[0]
20         errorMessage = res[1]
21     }
22
23     Component.onCompleted: {
24         newName.text = Functions.lastPartOfPath(path)
25     }
26
27     SilicaFlickable {
28         id: flickable
29         anchors.fill: parent
30         contentHeight: column.height
31         VerticalScrollDecorator { flickable: flickable }
32
33         Column {
34             id: column
35             anchors.left: parent.left
36             anchors.right: parent.right
37
38             DialogHeader {
39                 id: dialogHeader
40                 title: qsTr("Rename")
41                 acceptText: qsTr("Rename")
42             }
43
44             Label {
45                 anchors.left: parent.left
46                 anchors.right: parent.right
47                 anchors.leftMargin: Theme.paddingLarge
48                 anchors.rightMargin: Theme.paddingLarge
49                 text: qsTr("Give a new name for\n%1").arg(path)
50                 color: Theme.secondaryColor
51                 wrapMode: Text.Wrap
52             }
53
54             Spacer {
55                 height: 20
56             }
57
58             TextField {
59                 id: newName
60                 width: parent.width
61                 placeholderText: qsTr("New name")
62                 label: qsTr("New name")
63                 focus: true
64
65                 // return key on virtual keyboard accepts the dialog
66                 EnterKey.enabled: newName.text.length > 0
67                 EnterKey.iconSource: "image://theme/icon-m-enter-accept"
68                 EnterKey.onClicked: dialog.accept()
69             }
70         }
71     }
72 }
73
74