File: TweaksSettingsDlg.cpp

package info (click to toggle)
codelite 12.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (197 lines) | stat: -rw-r--r-- 7,041 bytes parent folder | download | duplicates (2)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 Eran Ifrah
// file name            : TweaksSettingsDlg.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "TweaksSettingsDlg.h"
#include "tweaks_settings.h"
#include "workspace.h"
#include <wx/choicdlg.h>
#include "windowattrmanager.h"
#include "macros.h"
#include <wx/msgdlg.h>
#include <wx/richmsgdlg.h>
#include "cl_defs.h"

TweaksSettingsDlg::TweaksSettingsDlg(wxWindow* parent)
    : TweaksSettingsDlgBase(parent)
{
    m_settings.Load();
    m_checkBoxEnableTweaks->SetValue( m_settings.IsEnableTweaks() );

    DoPopulateList();
    SetName("TweaksSettingsDlg");
    WindowAttrManager::Load(this);
}

TweaksSettingsDlg::~TweaksSettingsDlg()
{
    
    m_colourProperties.clear();
}

void TweaksSettingsDlg::OnWorkspaceOpenUI(wxUpdateUIEvent& event)
{
    event.Enable( clCxxWorkspaceST::Get()->IsOpen() );
}

void TweaksSettingsDlg::DoPopulateList()
{
    m_colourProperties.clear();
    // Get list of projects
    wxArrayString projects;
    clCxxWorkspaceST::Get()->GetProjectList( projects );

    // ----------------------------------------------------------------------
    // Add tab colours properties
    // ----------------------------------------------------------------------
    if ( m_settings.GetGlobalBgColour().IsOk() ) {
        wxVariant value;
        value << m_settings.GetGlobalBgColour();
        m_pgPropGlobalTabBG->SetValue( value );
    }

    if ( m_settings.GetGlobalFgColour().IsOk() ) {
        wxVariant value;
        value << m_settings.GetGlobalFgColour();
        m_pgPropGlobalTabFG->SetValue( value );
    }

    for(size_t i=0; i<projects.GetCount(); ++i) {
        const ProjectTweaks& pt = m_settings.GetProjectTweaks(projects.Item(i));
        // Image table
        m_pgMgr->Append( new wxFileProperty(projects.Item(i), wxPG_LABEL, pt.GetBitmapFilename()) );

        // Colours table
        wxPGProperty *parentProject = m_pgMgrTabColours->AppendIn(m_pgPropProjectsColours, new wxPropertyCategory(projects.Item(i)));
        wxString labelBG, labelFG;
        labelBG << projects.Item(i) << " tab label background colour";
        labelFG << projects.Item(i) << " tab label text colour";
        if ( pt.IsOk() ) {
            m_colourProperties.push_back( m_pgMgrTabColours->AppendIn(parentProject, new wxSystemColourProperty(labelBG, wxPG_LABEL, pt.GetTabBgColour() )) );
            m_colourProperties.push_back( m_pgMgrTabColours->AppendIn(parentProject, new wxSystemColourProperty(labelFG, wxPG_LABEL, pt.GetTabFgColour() )) );
            
        } else {
            wxPGProperty* prop(NULL);

            prop = m_pgMgrTabColours->AppendIn(parentProject, new wxSystemColourProperty(labelBG));
            prop->SetValueToUnspecified();
            m_colourProperties.push_back( prop );

            prop = m_pgMgrTabColours->AppendIn(parentProject, new wxSystemColourProperty(labelFG));
            prop->SetValueToUnspecified();
            m_colourProperties.push_back( prop );
        }
    }
}

void TweaksSettingsDlg::OnEnableTweaks(wxCommandEvent& event)
{
    m_settings.SetEnableTweaks( event.IsChecked() );
}

void TweaksSettingsDlg::OnEnableTweaksUI(wxUpdateUIEvent& event)
{
    event.Enable( m_checkBoxEnableTweaks->IsChecked() && clCxxWorkspaceST::Get()->IsOpen() );
}

void TweaksSettingsDlg::OnEnableTweaksCheckboxUI(wxUpdateUIEvent& event)
{
    event.Enable( clCxxWorkspaceST::Get()->IsOpen() );
}

void TweaksSettingsDlg::OnColourChanged(wxPropertyGridEvent& event)
{
    event.Skip();
    wxPGProperty* prop = event.GetProperty();
    CHECK_PTR_RET(prop);

    if ( prop == m_pgPropGlobalTabBG ) {
        // Global tab bg colour was modified
        wxColourPropertyValue cpv;
        cpv << prop->GetValue();
        m_settings.SetGlobalBgColour( cpv.m_colour );

    } else if ( prop == m_pgPropGlobalTabFG ) {
        // Global tab colour was modified
        wxColourPropertyValue cpv;
        cpv << prop->GetValue();
        m_settings.SetGlobalFgColour( cpv.m_colour );

    } else if ( prop->GetParent() ) {
        // project specific colour was changed
        wxColourPropertyValue cpv;
        cpv << prop->GetValue();

        if ( prop->GetLabel().Contains("text colour") ) {
            m_settings.GetProjectTweaks(prop->GetParent()->GetLabel()).SetTabFgColour( cpv.m_colour );

        } else if ( prop->GetLabel().Contains("background colour") ) {
            m_settings.GetProjectTweaks(prop->GetParent()->GetLabel()).SetTabBgColour( cpv.m_colour );

        }
    }
}
void TweaksSettingsDlg::OnImageSelected(wxPropertyGridEvent& event)
{
    wxPGProperty* prop = event.GetProperty();
    CHECK_PTR_RET(prop);

    wxString projectName = prop->GetLabel();
    m_settings.GetProjectTweaks(projectName).SetBitmapFilename( prop->GetValueAsString() );

    if ( !m_settings.HasFlag( TweaksSettings::kDontPromptForProjectReload ) ) {
        wxRichMessageDialog dlg(this, _("Icon changes require a workspace reload"), "CodeLite", wxOK|wxOK_DEFAULT|wxCANCEL|wxICON_INFORMATION);
        dlg.ShowCheckBox(_("Remember my answer"));
        if ( dlg.ShowModal() == wxID_OK ) {
            if ( dlg.IsCheckBoxChecked() ) {
                m_settings.EnableFlag( TweaksSettings::kDontPromptForProjectReload, true );
            }
        }
    }
}
void TweaksSettingsDlg::OnResetColours(wxCommandEvent& event)
{
    wxUnusedVar( event );
    PropPtrList_t::iterator iter = m_colourProperties.begin();
    for( ; iter != m_colourProperties.end(); ++iter ) {
        (*iter)->SetValueToUnspecified();
    }
    m_pgPropGlobalTabBG->SetValueToUnspecified();
    m_pgPropGlobalTabFG->SetValueToUnspecified();
    m_settings.ResetColours();
}

void TweaksSettingsDlg::OnEnableColoursTableUI(wxUpdateUIEvent& event)
{
#if defined(__WXGTK__)
#if CL_USE_NATIVEBOOK
    // Under GTK, when native books are enabled, the tab coloring is not
    // available
    event.Enable(false);
    return;
#endif
#endif

    event.Enable( m_checkBoxEnableTweaks->IsChecked() && clCxxWorkspaceST::Get()->IsOpen() );
}