File: editorsettingsbookmarkspanel.cpp

package info (click to toggle)
codelite 12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • 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 (136 lines) | stat: -rw-r--r-- 5,688 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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2008 by Eran Ifrah
// file name            : editorsettingsbookmarkspanel.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 "globals.h"
#include "editorsettingsbookmarkspanel.h"

EditorSettingsBookmarksPanel::EditorSettingsBookmarksPanel(wxWindow* parent)
    : EditorSettingsBookmarksBasePanel(parent)
    , TreeBookNode<EditorSettingsBookmarksPanel>()
    , m_previous(wxNOT_FOUND)
{
    m_highlightColor->SetColour(wxString(wxT("LIGHT BLUE")));

    // get the editor's options from the disk
    OptionsConfigPtr options = EditorConfigST::Get()->GetOptions();
    m_displaySelection->SetValue(options->GetDisplayBookmarkMargin());

    // These are localised inside m_bookMarkShape. However serialising the translated strings will break other
    // locales...
    const wxString UnlocalisedShapes[] = { wxTRANSLATE("Small Rectangle"),
                                           wxTRANSLATE("Rounded Rectangle"),
                                           wxTRANSLATE("Circle"),
                                           wxTRANSLATE("Small Arrow") };
    m_stringManager.AddStrings(
        sizeof(UnlocalisedShapes) / sizeof(wxString), UnlocalisedShapes, options->GetBookmarkShape(), m_bookMarkShape);

    for(size_t n = 0; n < CL_N0_OF_BOOKMARK_TYPES; ++n) {
        BookmarkData arr;
        wxColour col = options->GetBookmarkBgColour(n);
        if(!col.IsOk()) {
            col = options->GetBookmarkBgColour(0);
        }
        arr.bg = col;

        col = options->GetBookmarkFgColour(n);
        if(!col.IsOk()) {
            col = options->GetBookmarkFgColour(0);
        }
        arr.fg = col;

        arr.defaultLabel = m_choiceBMType->GetString(n); // Store the default  value
        arr.label = options->GetBookmarkLabel(n);
        if(!arr.label.empty()) {
            wxCHECK_RET(n < m_choiceBMType->GetCount(), "More bookmark types than there are Choice entries");
            m_choiceBMType->SetString(n, arr.label);
        }

        m_bookmarksData.push_back(arr);
    }
    ChangeSelection(0); // Fake a change to display the standard-bookmark values

    wxString val1 = EditorConfigST::Get()->GetString(wxT("WordHighlightColour"));
    if(val1.IsEmpty() == false) {
        m_highlightColor->SetColour(val1);
    }

    long alpha = EditorConfigST::Get()->GetInteger(wxT("WordHighlightAlpha"));
    if(alpha != wxNOT_FOUND) {
        m_spinCtrlHighlightAlpha->SetValue(alpha);
    }
    m_clearHighlitWords->SetValue(options->GetClearHighlitWordsOnFind());
}

void EditorSettingsBookmarksPanel::Save(OptionsConfigPtr options)
{
    options->SetDisplayBookmarkMargin(m_displaySelection->IsChecked());

    // Get the bookmark selection, unlocalised
    wxString bmShape = m_stringManager.GetStringSelection();
    if(bmShape.IsEmpty()) {
        bmShape = wxT("Small Arrow");
    }
    options->SetBookmarkShape(bmShape);

    ChangeSelection(m_choiceBMType->GetSelection()); // Fake a change to store any altered values

    for(size_t n = 0; n < CL_N0_OF_BOOKMARK_TYPES; ++n) {
        BookmarkData& arr = m_bookmarksData.at(n);
        options->SetBookmarkBgColour(arr.bg, n);
        options->SetBookmarkFgColour(arr.fg, n);
        options->SetBookmarkLabel(arr.label, n);
    }

    EditorConfigST::Get()->SetString(wxT("WordHighlightColour"), m_highlightColor->GetColour().GetAsString());
    EditorConfigST::Get()->SetInteger(wxT("WordHighlightAlpha"), (long)m_spinCtrlHighlightAlpha->GetValue());
    options->SetClearHighlitWordsOnFind(m_clearHighlitWords->IsChecked());
}

void EditorSettingsBookmarksPanel::ChangeSelection(int index)
{
    wxCHECK_RET(index < CL_N0_OF_BOOKMARK_TYPES, "Bookmark type out of range");

    if(m_previous >= 0) {
        // Store the current data in case it was just altered
        BookmarkData& arr = m_bookmarksData.at(m_previous);
        arr.bg = m_backgroundColor->GetColour();
        arr.fg = m_foregroundColor->GetColour();
        arr.label = m_BookmarkLabel->GetValue();
        if(m_BookmarkLabel->GetValue().empty()) {
            m_choiceBMType->SetString(m_previous, arr.defaultLabel);
        } else {
            m_choiceBMType->SetString(m_previous, arr.label);
        }
    }

    BookmarkData arr = m_bookmarksData.at(index);
    m_backgroundColor->SetColour(arr.bg);
    m_foregroundColor->SetColour(arr.fg);
    m_BookmarkLabel->ChangeValue(arr.label);

    m_previous = index;
}

void EditorSettingsBookmarksPanel::OnBookmarkChanged(wxCommandEvent& event) { ChangeSelection(event.GetSelection()); }