aboutsummaryrefslogtreecommitdiffstats
path: root/QtVsTools.Wizards/Common/GuiPage.xaml.cs
blob: 19be659b7d9cfdeaf31ccb8aca6b1061d2be8268 (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
49
50
51
/***************************************************************************************************
 Copyright (C) 2024 The Qt Company Ltd.
 SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
***************************************************************************************************/

using System.Windows;
using System.Windows.Controls;

namespace QtVsTools.Wizards.Common
{
    public partial class GuiPage : WizardPage
    {
        public bool IsClassWizardPage { get; set; } = false;
        public Visibility ClassPageVisible => IsClassWizardPage ? Visibility.Hidden : Visibility.Visible;
        public Visibility QObjectMacro => IsClassWizardPage ? Visibility.Visible : Visibility.Collapsed;

        public GuiPage()
        {
            InitializeComponent();
            DataContext = this;
            UpdateFileNames();
        }

        private void OnClassNameChanged(object sender, TextChangedEventArgs e)
        {
            UpdateFileNames();
        }

        private void OnLowerCaseFileNamesClick(object sender, RoutedEventArgs e)
        {
            UpdateFileNames();
        }

        private void UpdateFileNames()
        {
            var filename = ClassName.Text;
            if (LowerCaseFileNames.IsChecked.GetValueOrDefault())
                filename = filename.ToLower();

            // support namespaces in class name
            var index = filename.LastIndexOf(@":", System.StringComparison.Ordinal);
            if (index >= 0)
                filename = filename.Substring(index + 1);

            ClassHeaderFile.Text = filename + @".h";
            ClassSourceFile.Text = filename + @".cpp";
            UiFile.Text = filename + @".ui";
            QrcFile.Text = filename + @".qrc";
        }
    }
}