summaryrefslogtreecommitdiff
path: root/src/plugins/projectexplorer/jsonwizard/jsonfilepage.cpp
blob: 6b23983f3b77fbad7b50eb5e8433839172b8c8b5 (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
44
45
46
47
48
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "jsonfilepage.h"

#include "jsonwizard.h"

#include <utils/filepath.h>

using namespace Utils;

namespace ProjectExplorer {

JsonFilePage::JsonFilePage(QWidget *parent)
    : FileWizardPage(parent)
{
    setAllowDirectoriesInFileSelector(true);
}

void JsonFilePage::initializePage()
{
    auto wiz = qobject_cast<JsonWizard *>(wizard());
    if (!wiz)
        return;

    if (fileName().isEmpty())
        setFileName(wiz->stringValue(QLatin1String("InitialFileName")));
    if (filePath().isEmpty())
        setPath(wiz->stringValue(QLatin1String("InitialPath")));
    setDefaultSuffix(wiz->stringValue("DefaultSuffix"));
}

bool JsonFilePage::validatePage()
{
    if (filePath().isEmpty() || fileName().isEmpty())
        return false;

    const FilePath dir = filePath();
    if (!dir.isDir())
        return false;

    const FilePath target = dir.resolvePath(fileName());

    wizard()->setProperty("TargetPath", target.toString());
    return true;
}

} // namespace ProjectExplorer