summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/dialog-manager.h
blob: fc4cd9b8b3960923e0a129513bab8d64331db5f2 (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
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
// SPDX-License-Identifier: GPL-2.0-or-later

#ifndef INKSCAPE_UI_DIALOG_MANAGER_H
#define INKSCAPE_UI_DIALOG_MANAGER_H

#include <glibmm/keyfile.h>
#include <gtkmm/window.h>
#include <map>
#include <set>
#include <memory>
#include <optional>
#include <vector>

namespace Inkscape {
namespace UI {
namespace Dialog {

class DialogWindow;
class DialogBase;
class DialogContainer;

struct window_position_t
{
    int x, y, width, height;
};

// try to read window's geometry
std::optional<window_position_t> dm_get_window_position(Gtk::Window &window);

// restore window's geometry
void dm_restore_window_position(Gtk::Window &window, const window_position_t &position);

class DialogManager
{
public:
    static DialogManager &singleton();

    // store complete dialog window state (including its container state)
    void store_state(DialogWindow &wnd);

    // return true if dialog 'type' should be opened as floating
    bool should_open_floating(const Glib::ustring& dialog_type);

    // find instance of dialog 'type' in one of currently open floating dialog windows
    DialogBase *find_floating_dialog(const Glib::ustring& dialog_type);

    // find window hosting floating dialog
    DialogWindow* find_floating_dialog_window(const Glib::ustring& dialog_type);

    // find floating window state hosting dialog 'code', if there was one
    std::shared_ptr<Glib::KeyFile> find_dialog_state(const Glib::ustring& dialog_type);

    // remove dialog floating state
    void remove_dialog_floating_state(const Glib::ustring& dialog_type);

    // save configuration of docked and floating dialogs
    void save_dialogs_state(DialogContainer *docking_container);

    // restore state of dialogs
    void restore_dialogs_state(DialogContainer *docking_container, bool include_floating);

    // find all floating dialog windows
    std::vector<DialogWindow*> get_all_floating_dialog_windows();

    // show/hide dialog window and keep track of it
    void set_floating_dialog_visibility(DialogWindow* wnd, bool show);

private:
    DialogManager() = default;
    ~DialogManager() = default;

    std::vector<Glib::ustring> count_dialogs(const Glib::KeyFile *state) const;
    void load_transient_state(Glib::KeyFile *keyfile);
    void dialog_defaults();

    // transient dialog state for floating windows user closes
    std::map<std::string, std::shared_ptr<Glib::KeyFile>> _floating_dialogs;
    // temp set used when dialogs are hidden (F12 toggle)
    std::set<DialogWindow*> _hidden_dlg_windows;
};

} // namespace Dialog
} // namespace UI
} // namespace Inkscape

#endif

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :