root/trunk/AbbSettingsPage.cpp

Revision 5, 4.2 kB (checked in by qbert, 3 years ago)

Initial ( and last :( ) commit

Line 
1 // AbbSettingsPage.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "Elephant.h"
6 #include "AbbSettingsPage.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 // CAbbSettingsPage dialog
16
17
18 CAbbSettingsPage::CAbbSettingsPage(CWnd* pParent /*=NULL*/)
19    
20 {
21     //{{AFX_DATA_INIT(CAbbSettingsPage)
22     m_maintainTabs = FALSE;
23     m_abb = _T("");
24     m_expandsTo = _T("");
25     m_csCursor = _T("");
26     //}}AFX_DATA_INIT
27 }
28
29
30 void CAbbSettingsPage::DoDataExchange(CDataExchange* pDX)
31 {
32     CDialog::DoDataExchange(pDX);
33     //{{AFX_DATA_MAP(CAbbSettingsPage)
34     DDX_Control(pDX, IDC_EDIT2, m_expandsToCtrl);
35     DDX_Control(pDX, IDC_LIST1, m_abbsCtrl);
36     DDX_Control(pDX, IDC_COMBO1, m_cursor);
37     DDX_Control(pDX, IDC_BUTTON3, m_remove);
38     DDX_Control(pDX, IDC_BUTTON1, m_add);
39     DDX_Check(pDX, IDC_CHECK1, m_maintainTabs);
40     DDX_Text(pDX, IDC_EDIT1, m_abb);
41     DDX_Text(pDX, IDC_EDIT2, m_expandsTo);
42     DDX_CBString(pDX, IDC_COMBO1, m_csCursor);
43     //}}AFX_DATA_MAP
44 }
45
46 /*
47
48
49
50 asdf
51 asdf
52
53
54 */
55
56 BEGIN_MESSAGE_MAP(CAbbSettingsPage, CDialog)
57     //{{AFX_MSG_MAP(CAbbSettingsPage)
58     ON_BN_CLICKED(IDC_BUTTON1, OnAdd)
59     ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
60     ON_BN_CLICKED(IDC_BUTTON3, OnRemove)
61     //}}AFX_MSG_MAP
62 END_MESSAGE_MAP()
63
64 /////////////////////////////////////////////////////////////////////////////
65 // CAbbSettingsPage message handlers
66
67 BOOL CAbbSettingsPage::OnInitDialog()
68 {
69     CDialog::OnInitDialog();
70    
71     InitCursors();
72
73     m_abbsCtrl.InsertColumn(0,"Abbreviation",LVCFMT_LEFT,130);
74     m_abbsCtrl.InsertColumn(1,"Expands To",LVCFMT_LEFT,130);
75     m_abbsCtrl.InsertColumn(2,"Cursor",LVCFMT_LEFT,80);
76     m_abbsCtrl.InsertColumn(3,"Tabs",LVCFMT_LEFT,80);
77
78     SetupListCtrl(&m_abbsCtrl);
79     SetupButton(&m_add);
80     SetupButton(&m_remove);
81
82     Restore();
83     return TRUE;  // return TRUE unless you set the focus to a control
84                   // EXCEPTION: OCX Property Pages should return FALSE
85 }
86
87 void CAbbSettingsPage::OnAdd()
88 {
89     UpdateData();
90
91     if ( m_abb == "" )
92     {
93         ElephantMessageBox("Could you add the 'abbreviation' part for this abbreviation ? ",this);
94         m_abbsCtrl.SetFocus();
95         return;
96     }
97
98     if ( m_expandsTo == "" )
99     {
100         ElephantMessageBox("Could you add the 'abbreviation' part for this abbreviation ? ",this);
101         m_expandsToCtrl.SetFocus();
102         return;
103     }
104
105
106     int count = m_abbsCtrl.GetItemCount();
107    
108     vector<string> v;
109     GetAllListCtrlItems(&m_abbsCtrl,&v,0);
110
111     int foundNo = 0;
112     bool found = false;
113
114     string abb = m_abb.GetBuffer(0);
115     for ( int i = 0 ; i < v.size(); i++ )
116     {
117        
118         if ( abb == v[i].c_str() )
119         {
120            
121             found = true;
122             foundNo = i;
123             break;
124         }
125     }
126    
127     if ( found )
128     {
129         //AfxMessageBox("here");
130         m_abbsCtrl.SetItemText(foundNo,0,m_abb);
131         count = foundNo;
132     }
133     else {
134         m_abbsCtrl.InsertItem(count,m_abb);
135     }
136    
137     m_abbsCtrl.SetItemText(count,1,WhiteSpace::ReplaceWithCodes(m_expandsTo.GetBuffer(0)).c_str());
138     if ( m_csCursor == "Cursor" )   m_abbsCtrl.SetItemText(count,2,ITOA(m_expandsTo.GetLength() ).c_str());
139     else    m_abbsCtrl.SetItemText(count,2,m_csCursor);
140     m_abbsCtrl.SetItemText(count,3,m_maintainTabs ? "true" : "false");
141
142    
143
144
145
146    
147 }
148
149 void CAbbSettingsPage::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
150 {
151     // TODO: Add your control notification handler code here
152    
153
154     POSITION pos = m_abbsCtrl.GetFirstSelectedItemPosition();
155     if ( !pos) return;
156    
157     int nItem = m_abbsCtrl.GetNextSelectedItem(pos);   
158
159     CString key = m_abbsCtrl.GetItemText(nItem,0);
160     CString value = m_abbsCtrl.GetItemText(nItem,1);
161    
162
163     CString expands = WhiteSpace::ReplaceCodesWithWhite(value.GetBuffer(0) ).c_str() ;
164     CString cursor = m_abbsCtrl.GetItemText(nItem,2);
165     bool maintain = m_abbsCtrl.GetItemText(nItem,3) == "true" ? true : false;
166
167
168     m_abb = key;
169     m_expandsTo = expands;
170     m_maintainTabs = maintain; 
171     m_csCursor = cursor;
172
173    
174
175
176     UpdateData(FALSE);
177    
178
179 }
180
181 void CAbbSettingsPage::OnRemove()
182 {
183     vector<string> files;
184     GetSelListCtrlItems(&m_abbsCtrl,&files);
185
186     for ( int i = 0 ; i < files.size();i++)
187     {
188         Globals::settings->abbreviations.erase(files[i]);
189     }
190    
191     DeleteAllSelectedItems(&m_abbsCtrl);
192 }
Note: See TracBrowser for help on using the browser.