File: FileSelectionRequest.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (131 lines) | stat: -rw-r--r-- 3,071 bytes parent folder | download | duplicates (4)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#pragma once

#include <stdexcept>
#include "imessagebus.h"
#include "imapformat.h"

namespace radiant
{

/**
 * Message sent when the backend code needs the user to 
 * browse and select a file.
 */
class FileSelectionRequest :
    public radiant::IMessage
{
public:
    enum class Mode
    {
        Open,
        Save,
    };

    class Result
    {
    public:
        // The full path of the selected file
        std::string fullPath;

        // For save dialogs, a specific map format might have been selected
        std::string mapFormatName;
    };

private:
    Mode _mode;
    std::string _type;
    std::string _title;
    std::string _defaultFile;
    Result _result;

public:
    /**
     * Asks the UI code to select a file to load or save.
     *
     * @param mode
     * Whether this is an open operation or a save operation (changes file
     * dialog behaviour).
     *
     * @param title
     * The title to display on the dialog, such as "Open map" or "Export
     * selection".
     *
     * @param type: the file type to be loaded ("map", "prefab" or "region")
     *
     * @returns
     * The info structure of the file selection, the member fullPath of which will
     * be empty string if no selection was made.
     */
    FileSelectionRequest(Mode mode, const std::string& title, const std::string& type) :
        FileSelectionRequest(mode, title, type, std::string())
    {}

    /**
     * Asks the UI code to select a file to load or save.
     *
     * @param mode
     * Whether this is an open operation or a save operation (changes file
     * dialog behaviour).
     *
     * @param title
     * The title to display on the dialog, such as "Open map" or "Export
     * selection".
     *
     * @param type: the file type to be loaded ("map", "prefab" or "region")
     *
     * @param defaultFile
     * The default file path which should already be selected when the dialog
     * is displayed.
     *
     * @returns
     * The info structure of the file selection, the member fullPath of which will
     * be empty string if no selection was made.
     */
    FileSelectionRequest(Mode mode, const std::string& title,
                         const std::string& type, const std::string& defaultFile) :
        _mode(mode),
        _type(type),
        _title(title),
        _defaultFile(defaultFile)
    {}

    std::size_t getId() const override
    {
        return IMessage::Type::FileSelectionRequest;
    }

    const std::string& getType() const
    {
        return _type;
    }

    const std::string& getTitle() const
    {
        return _title;
    }

    Mode getMode() const
    {
        return _mode;
    }

    const std::string& getDefaultFile() const
    {
        return _defaultFile;
    }

    // Returns the result of the file selection operation
    // The file path is empty if nothing was selected or the
    // selection has been cancelled
    const Result& getResult() const
    {
        return _result;
    }

    void setResult(const Result& result)
    {
        _result = result;
    }
};

}