root/trunk/KeywordColorsPage.cpp

Revision 5, 4.6 kB (checked in by qbert, 6 years ago)

Initial ( and last :( ) commit

Line 
1 // KeywordColorsPage.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "Elephant.h"
6 #include "KeywordColorsPage.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 /////////////////////////////////////////////////////////////////////////////
15 // CKeywordColorsPage dialog
16
17
18 CKeywordColorsPage::CKeywordColorsPage(CWnd* pParent /*=NULL*/)
19    
20 {
21     //{{AFX_DATA_INIT(CKeywordColorsPage)
22     m_keyword = _T("");
23     m_csKeyword = _T("");
24     //}}AFX_DATA_INIT
25 }
26
27
28 void CKeywordColorsPage::DoDataExchange(CDataExchange* pDX)
29 {
30     CDialog::DoDataExchange(pDX);
31     //{{AFX_DATA_MAP(CKeywordColorsPage)
32     DDX_Control(pDX, IDC_LIST1, m_keywordCtrl);
33     DDX_Control(pDX, IDC_COMBO1, m_keywordTypes);
34     DDX_Control(pDX, IDC_BUTTON6, m_remove);
35     DDX_Control(pDX, IDC_BUTTON3, m_add);
36     DDX_Control(pDX, IDC_BUTTON2, m_textBack);
37     DDX_Control(pDX, IDC_BUTTON1, m_textFore);
38     DDX_Text(pDX, IDC_EDIT1, m_keyword);
39     DDX_CBString(pDX, IDC_COMBO1, m_csKeyword);
40     //}}AFX_DATA_MAP
41     DDX_XTColorPicker(pDX, IDC_BUTTON2, m_clrBack);
42     DDX_XTColorPicker(pDX, IDC_BUTTON1, m_clrFore);
43 }
44
45
46 BEGIN_MESSAGE_MAP(CKeywordColorsPage, CDialog)
47     //{{AFX_MSG_MAP(CKeywordColorsPage)
48     ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
49     ON_BN_CLICKED(IDC_BUTTON1, OnButton1)   
50     ON_BN_CLICKED(IDC_BUTTON4, OnCommitChanges)
51     ON_BN_CLICKED(IDC_BUTTON3, OnAdd)
52     ON_BN_CLICKED(IDC_BUTTON6, OnRemove)
53     //}}AFX_MSG_MAP
54 END_MESSAGE_MAP()
55
56 /////////////////////////////////////////////////////////////////////////////
57 // CKeywordColorsPage message handlers
58
59 BOOL CKeywordColorsPage::OnInitDialog()
60 {
61     CDialog::OnInitDialog();
62    
63     InitCombo();
64     m_textBack.ShowText(true);
65     m_textFore.ShowText(true);
66    
67     // TODO: Add extra initialization here
68     m_keywordCtrl.InsertColumn(0,"Keyword",LVCFMT_LEFT,360);
69     SetupListCtrl(&m_keywordCtrl);
70
71     OnSelchangeCombo1();
72
73     return TRUE;  // return TRUE unless you set the focus to a control
74                   // EXCEPTION: OCX Property Pages should return FALSE
75 }
76
77 void CKeywordColorsPage::OnSelchangeCombo1()
78 {
79        
80     UpdateData();
81     CString colorKeyword = m_csKeyword + "_color";
82    
83     m_keywordCtrl.DeleteAllItems();
84
85     vector<string> keywords;
86     Split(Globals::settings->colorSettings->settings->GetCache(m_csKeyword.GetBuffer(0)),",",keywords);
87    
88     for (int i = 0;i < keywords.size();i ++ )
89     {
90         m_keywordCtrl.InsertItem(i,keywords[i].c_str());
91     }
92
93     m_clrFore = Globals::settings->colorSettings->colors[colorKeyword.GetBuffer(0)].fore;
94     m_clrBack = Globals::settings->colorSettings->colors[colorKeyword.GetBuffer(0)].back;
95     UpdateData(FALSE);
96        
97 }
98
99 void CKeywordColorsPage::OnButton1()
100 {
101 //  AfxMessageBox("HERE");
102    
103 }
104
105 void CKeywordColorsPage::OnSelendokCombo1()
106 {
107     // TODO: Add your control notification handler code here
108     CString buf;
109     m_keywordTypes.GetLBText(m_keywordTypes.GetCurSel(),buf);
110 // 
111 //  m_keywordTypes.Gets
112     AfxMessageBox(buf);
113 }
114
115 void CKeywordColorsPage::OnCommitChanges()
116 {
117     UpdateData();
118
119     CString colorKeyword = m_csKeyword + "_color";
120     Globals::settings->colorSettings->colors[colorKeyword.GetBuffer(0)].fore = m_clrFore;
121     Globals::settings->colorSettings->colors[colorKeyword.GetBuffer(0)].back= m_clrBack;
122     AfxMessageBox("Changes saved.");
123     //  AfxMessageBox(ITOA(m_clrFore) .c_str() );
124 //  AfxMessageBox(ITOA(Globals::settings->colorSettings->styleFore[index]).c_str() );
125 }
126
127 void CKeywordColorsPage::OnAdd()
128 {
129
130     UpdateData();
131
132     if ( m_csKeyword == "Comments" ) return;
133     if ( m_csKeyword == "Numbers" ) return;
134
135     string strWords = Globals::settings->colorSettings->settings->GetCache(m_csKeyword.GetBuffer(0));
136    
137     vector<string> words;
138     Split(strWords,",",words);
139    
140     words.push_back(m_keyword.GetBuffer(0));
141    
142     m_keywordCtrl.InsertItem(m_keywordCtrl.GetItemCount(),m_keyword);
143    
144     Globals::settings->colorSettings->settings->SetCache(m_csKeyword.GetBuffer(0),Join(words,","));
145    
146 }
147
148 void CKeywordColorsPage::OnRemove()
149 {
150     UpdateData();
151     vector<string> selWords;   
152     GetSelListCtrlItems(&m_keywordCtrl,&selWords);
153
154     string strWords = Globals::settings->colorSettings->settings->GetCache(m_csKeyword.GetBuffer(0));
155     vector<string> baseWords;
156     Split(strWords,",",baseWords);
157 //  AfxMessageBox(ITOA(baseWords.size() ).c_str() );
158 //  AfxMessageBox(ITOA(selWords.size() ).c_str() );
159
160     RemoveFromVector(baseWords,selWords);
161     Globals::settings->colorSettings->settings->SetCache(m_csKeyword.GetBuffer(0),Join(baseWords,","));
162 //  AfxMessageBox(Join(baseWords,",").c_str() );
163 //  AfxMessageBox(ITOA(baseWords.size() ).c_str() );
164     DeleteAllSelectedItems(&m_keywordCtrl);
165    
166 }
Note: See TracBrowser for help on using the browser.