root/trunk/TagSetsPage.cpp

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

Initial ( and last :( ) commit

Line 
1 // TagSetsPage.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "Elephant.h"
6 #include "TagSetsPage.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 // CTagSetsPage dialog
16
17
18 CTagSetsPage::CTagSetsPage(CWnd* pParent /*=NULL*/)
19    
20 {
21     //{{AFX_DATA_INIT(CTagSetsPage)
22     //}}AFX_DATA_INIT
23 }
24
25
26 void CTagSetsPage::DoDataExchange(CDataExchange* pDX)
27 {
28     CDialog::DoDataExchange(pDX);
29     //{{AFX_DATA_MAP(CTagSetsPage)
30     DDX_Control(pDX, IDC_COMBO1, m_tagSets);
31     DDX_Control(pDX, IDC_LIST1, m_filesCtrl);
32     DDX_Control(pDX, IDC_BUTTON3, m_remove);
33     DDX_Control(pDX, IDC_BUTTON2, m_add);
34     DDX_Control(pDX, IDC_BUTTON1, m_newSet);
35     //}}AFX_DATA_MAP
36 }
37
38
39 BEGIN_MESSAGE_MAP(CTagSetsPage, CDialog)
40     //{{AFX_MSG_MAP(CTagSetsPage)
41     ON_BN_CLICKED(IDC_BUTTON1, OnAdd)
42     ON_BN_CLICKED(IDC_BUTTON3, OnRemove)
43     ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
44     ON_BN_CLICKED(IDC_BUTTON2, OnNewSet)
45     //}}AFX_MSG_MAP
46 END_MESSAGE_MAP()
47
48 /////////////////////////////////////////////////////////////////////////////
49 // CTagSetsPage message handlers
50
51 BOOL CTagSetsPage::OnInitDialog()
52 {
53     CDialog::OnInitDialog();
54    
55     SetupButton(&m_add );
56     SetupButton(&m_remove);
57     SetupButton(&m_newSet);
58
59
60     m_filesCtrl.InsertColumn(0,"File Path",LVCFMT_LEFT,330);
61    
62     SetupListCtrl(&m_filesCtrl);
63
64     vector<string> keys;
65
66     GetKeysForMap(Globals::settings->tagSets,keys);
67     for ( int i = 0;i < keys.size();i++) {
68         m_tagSets.AddString(keys[i].c_str() );
69
70     }
71    
72     m_tagSets.SetCurSel(0);
73     OnSelchangeCombo1();
74    
75     return TRUE;  // return TRUE unless you set the focus to a control
76                   // EXCEPTION: OCX Property Pages should return FALSE
77 }
78
79 void CTagSetsPage::OnAdd()
80 {
81     UpdateData();
82
83     CString currentSet ;
84     m_tagSets.GetLBText(m_tagSets.GetCurSel(),currentSet);
85     vector<string> files;
86     GetFilesFromCFileDialog(Globals::lastDir, files,"d");
87
88     for ( int i = 0, count = m_filesCtrl.GetItemCount();i < files.size();i++ ,count++)
89     {
90         Globals::settings->tagSets[(LPCSTR)currentSet].push_back(files[i]);
91         m_filesCtrl.InsertItem(count,files[i].c_str() );
92     }
93    
94
95    
96 }
97
98 void CTagSetsPage::OnRemove()
99 {
100
101     vector<int> deletes;
102     vector<string> files;
103
104     CString currentSet ;
105     m_tagSets.GetLBText(m_tagSets.GetCurSel(),currentSet);
106
107     POSITION pos = m_filesCtrl.GetFirstSelectedItemPosition();
108     if (pos == NULL)
109         TRACE0("No items were selected!\n");
110     else
111     {
112         while (pos)
113         {
114             int nItem = m_filesCtrl.GetNextSelectedItem(pos);
115             deletes.push_back(nItem);
116             files.push_back(m_filesCtrl.GetItemText(nItem,0).GetBuffer(0 ) );
117             // you could do your own processing on nItem here
118         }
119     }
120
121     for (int i = 0; i < deletes.size();i++) {
122         m_filesCtrl.DeleteItem(deletes[i] - i );
123         RemoveFileFromMap(Globals::settings->tagSets,currentSet.GetBuffer(0),files[i]);
124     }
125
126    
127 }
128
129 void CTagSetsPage::OnSelchangeCombo1()
130 {
131     UpdateData();
132     m_filesCtrl.DeleteAllItems();
133     CString _buf;
134     m_tagSets.GetLBText(m_tagSets.GetCurSel(),_buf );
135     string buf = _buf.GetBuffer(0);
136
137     for ( int i = 0; i < Globals::settings->tagSets[buf].size();i++)
138     {
139         m_filesCtrl.InsertItem(0,Globals::settings->tagSets[buf][i].c_str() );
140
141     }
142
143    
144 }
145
146 void CTagSetsPage::OnNewSet()
147 {
148     string tagSet = GetTextFromUser("Enter new tag set name");
149
150     if ( tagSet != "ELEPHANT_CANCELED")
151     {
152         m_tagSets.AddString(tagSet.c_str());
153         m_tagSets.SetCurSel(m_tagSets.GetCount() - 1);
154         OnSelchangeCombo1();
155
156     }
157    
158 }
Note: See TracBrowser for help on using the browser.