File: DeclarationSelector.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 (116 lines) | stat: -rw-r--r-- 3,540 bytes parent folder | download | duplicates (3)
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
#pragma once

#include <vector>
#include <sigc++/connection.h>

#include "idecltypes.h"
#include "ui/iwindowstate.h"
#include <wx/panel.h>
#include <wx/sizer.h>

#include "ui/ideclpreview.h"
#include "../dataview/DeclarationTreeView.h"
#include "wxutil/PanedPosition.h"

namespace wxutil
{

class DeclFileInfo;

/**
 * Common implementation of a declaration selector widget that can be added to a dialog.
 * It features a Declaration Tree View with an associated toolbar for favourite management.
 * Preview widgets can optionally be appended to the right or the bottom of the tree view.
 */
class DeclarationSelector :
    public wxPanel,
    public ui::IPersistableObject
{
private:
    decl::Type _declType;

    const DeclarationTreeView::Columns& _columns;
    DeclarationTreeView* _treeView;

    wxPanel* _leftPanel;
    wxPanel* _rightPanel;

    wxSizer* _treeVbox;

    // The set of preview widgets attached to this selector
    std::vector<ui::IDeclarationPreview*> _previews;

    DeclFileInfo* _declFileInfo;

    std::unique_ptr<PanedPosition> _panedPosition;

    sigc::connection _declsReloaded;

public:
    // Construct a selector widget with the default set of tree view columns
    DeclarationSelector(wxWindow* parent, decl::Type declType);

    // Construct a selector widget with the given set of tree view columns
    DeclarationSelector(wxWindow* parent, decl::Type declType, const DeclarationTreeView::Columns& columns);

    ~DeclarationSelector() override;

    /**
     * Return the declaration selected by the user, or an empty string if there
     * was no selection.
     */
    virtual std::string GetSelectedDeclName() const;

    /**
     * Set the given declaration name as the current selection, highlighting it
     * in the tree view.
     *
     * @param declName
     * The fullname of the declaration to select, or the empty string if there
     * should be no selection.
     */
    virtual void SetSelectedDeclName(const std::string& declName);

    // Set the focus on the treeview widget
    void FocusTreeView();

    void loadFromPath(const std::string& registryKey) override;
    void saveToPath(const std::string& registryKey) override;

    // (Re-)populate the tree view, must be implemented by subclasses
    virtual void Populate() = 0;

protected:
    DeclarationTreeView* GetTreeView() const;

    // Adds a preview widget to the right of the tree view
    void AddPreviewToRightPane(ui::IDeclarationPreview* preview, int sizerProportion = 1);
    void AddPreviewToBottom(ui::IDeclarationPreview* preview, int sizerProportion = 0);

    void AddWidgetToBottom(wxWindow* widget, int sizerProportion = 0);

    const DeclarationTreeView::Columns& GetColumns() const;

    void PopulateTreeView(const IResourceTreePopulator::Ptr& populator);

    // Event method invoked when the tree view selection has been changed
    virtual void onTreeViewSelectionChanged()
    {}

    // Event method invoked when the tree view selection has been activated (Enter key or double-click)
    // Returns true to indicate that the event has been handled and should not be further processed
    virtual bool onTreeViewItemActivated()
    {
        return false;
    }

    // Default tree view columns. Subclasses can use a different set of columns if needed
    static const DeclarationTreeView::Columns& CreateDefaultColumns();

private:
    void createTreeView(wxWindow* parent);
    void onTreeViewSelectionChanged(wxDataViewEvent& ev);
    void onTreeViewItemActivated(wxDataViewEvent& ev);
};

}