1 |
786 |
skrzyp |
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####
|
2 |
|
|
// -------------------------------------------
|
3 |
|
|
// This file is part of the eCos host tools.
|
4 |
|
|
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
5 |
|
|
//
|
6 |
|
|
// This program is free software; you can redistribute it and/or modify
|
7 |
|
|
// it under the terms of the GNU General Public License as published by
|
8 |
|
|
// the Free Software Foundation; either version 2 or (at your option) any
|
9 |
|
|
// later version.
|
10 |
|
|
//
|
11 |
|
|
// This program is distributed in the hope that it will be useful, but
|
12 |
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
// General Public License for more details.
|
15 |
|
|
//
|
16 |
|
|
// You should have received a copy of the GNU General Public License
|
17 |
|
|
// along with this program; if not, write to the
|
18 |
|
|
// Free Software Foundation, Inc., 51 Franklin Street,
|
19 |
|
|
// Fifth Floor, Boston, MA 02110-1301, USA.
|
20 |
|
|
// -------------------------------------------
|
21 |
|
|
// ####ECOSHOSTGPLCOPYRIGHTEND####
|
22 |
|
|
// conflictsdlg.cpp :
|
23 |
|
|
//
|
24 |
|
|
//===========================================================================
|
25 |
|
|
//#####DESCRIPTIONBEGIN####
|
26 |
|
|
//
|
27 |
|
|
// Author(s): julians
|
28 |
|
|
// Contact(s): julians
|
29 |
|
|
// Date: 2000/09/06
|
30 |
|
|
// Version: $Id: conflictsdlg.cpp,v 1.4 2001/07/09 14:21:32 julians Exp $
|
31 |
|
|
// Purpose:
|
32 |
|
|
// Description: Implementation file for the ecResolveConflictsDialog
|
33 |
|
|
// Requires:
|
34 |
|
|
// Provides:
|
35 |
|
|
// See also:
|
36 |
|
|
// Known bugs:
|
37 |
|
|
// Usage:
|
38 |
|
|
//
|
39 |
|
|
//####DESCRIPTIONEND####
|
40 |
|
|
//
|
41 |
|
|
//===========================================================================
|
42 |
|
|
|
43 |
|
|
// ============================================================================
|
44 |
|
|
// declarations
|
45 |
|
|
// ============================================================================
|
46 |
|
|
|
47 |
|
|
// ----------------------------------------------------------------------------
|
48 |
|
|
// headers
|
49 |
|
|
// ----------------------------------------------------------------------------
|
50 |
|
|
#ifdef __GNUG__
|
51 |
|
|
#pragma implementation "conflictsdlg.h"
|
52 |
|
|
#endif
|
53 |
|
|
|
54 |
|
|
// Includes other headers for precompiled compilation
|
55 |
|
|
#include "ecpch.h"
|
56 |
|
|
|
57 |
|
|
#ifdef __BORLANDC__
|
58 |
|
|
#pragma hdrstop
|
59 |
|
|
#endif
|
60 |
|
|
|
61 |
|
|
#include "configtool.h"
|
62 |
|
|
#include "conflictsdlg.h"
|
63 |
|
|
#include "conflictwin.h"
|
64 |
|
|
#include "solutionswin.h"
|
65 |
|
|
#include "configtooldoc.h"
|
66 |
|
|
#include "configtoolview.h"
|
67 |
|
|
#include "configtree.h"
|
68 |
|
|
|
69 |
|
|
#include "wx/cshelp.h"
|
70 |
|
|
|
71 |
|
|
BEGIN_EVENT_TABLE(ecResolveConflictsDialog, ecDialog)
|
72 |
|
|
EVT_BUTTON(ecID_CONFLICTS_ALL, ecResolveConflictsDialog::OnAll)
|
73 |
|
|
EVT_BUTTON(ecID_CONFLICTS_NONE, ecResolveConflictsDialog::OnNone)
|
74 |
|
|
EVT_BUTTON(ecID_CONFLICTS_CONTINUE, ecResolveConflictsDialog::OnContinue)
|
75 |
|
|
EVT_UPDATE_UI(ecID_CONFLICTS_ALL, ecResolveConflictsDialog::OnUpdateAll)
|
76 |
|
|
EVT_UPDATE_UI(ecID_CONFLICTS_NONE, ecResolveConflictsDialog::OnUpdateNone)
|
77 |
|
|
EVT_LIST_ITEM_SELECTED(ecID_CONFLICTS_CONFLICTS, ecResolveConflictsDialog::OnConflictSelected)
|
78 |
|
|
EVT_LIST_ITEM_DESELECTED(ecID_CONFLICTS_CONFLICTS, ecResolveConflictsDialog::OnConflictDeselected)
|
79 |
|
|
EVT_INIT_DIALOG(ecResolveConflictsDialog::OnInitDialog)
|
80 |
|
|
END_EVENT_TABLE()
|
81 |
|
|
|
82 |
|
|
// ----------------------------------------------------------------------------
|
83 |
|
|
// main frame
|
84 |
|
|
// ----------------------------------------------------------------------------
|
85 |
|
|
|
86 |
|
|
// Frame constructor
|
87 |
|
|
ecResolveConflictsDialog::ecResolveConflictsDialog(wxWindow* parent, std::list<CdlConflict> conflicts, CdlTransaction transaction, wxList *parConflictsOfInterest):
|
88 |
|
|
m_conflicts(conflicts),
|
89 |
|
|
m_Transaction(transaction),
|
90 |
|
|
m_parConflictsOfInterest(parConflictsOfInterest),
|
91 |
|
|
m_Map(wxKEY_INTEGER)
|
92 |
|
|
|
93 |
|
|
{
|
94 |
|
|
// Stop values from being changed by other mechanisms during the
|
95 |
|
|
// duration of this dialog.
|
96 |
|
|
wxGetApp().LockValues();
|
97 |
|
|
|
98 |
|
|
m_conflictsCtrl = NULL;
|
99 |
|
|
m_solutionsCtrl = NULL;
|
100 |
|
|
|
101 |
|
|
SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
|
102 |
|
|
|
103 |
|
|
ecDialog::Create(parent, ecID_RESOLVE_CONFLICTS_DIALOG, _("Resolve conflicts"),
|
104 |
|
|
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
|
105 |
|
|
|
106 |
|
|
std::list<CdlConflict>::const_iterator conf_i;
|
107 |
|
|
for (conf_i= m_conflicts.begin (); conf_i != m_conflicts.end (); conf_i++)
|
108 |
|
|
{ // for each conflict
|
109 |
|
|
int nSolutions = (*conf_i)->get_solution().size();
|
110 |
|
|
SolutionInfo *pInfo = (SolutionInfo *) malloc(sizeof(SolutionInfo)+(nSolutions-1)*sizeof(int));
|
111 |
|
|
pInfo->nCount = nSolutions;
|
112 |
|
|
int i;
|
113 |
|
|
for ( i = 0; i < nSolutions; i++)
|
114 |
|
|
{
|
115 |
|
|
pInfo->arItem[i] = SolutionInfo::CHECKED;
|
116 |
|
|
}
|
117 |
|
|
m_Map.Put((long) *conf_i, (wxObject*) pInfo);
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
CreateControls(this);
|
121 |
|
|
|
122 |
|
|
Centre(wxBOTH);
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
ecResolveConflictsDialog::~ecResolveConflictsDialog()
|
126 |
|
|
{
|
127 |
|
|
m_Map.BeginFind();
|
128 |
|
|
#if wxCHECK_VERSION(2, 6, 0)
|
129 |
|
|
wxHashTable::Node* node = NULL;
|
130 |
|
|
while ((node = m_Map.Next()))
|
131 |
|
|
{
|
132 |
|
|
SolutionInfo *pInfo = (SolutionInfo*) node->GetData();
|
133 |
|
|
#else
|
134 |
|
|
wxNode* node = NULL;
|
135 |
|
|
while ((node = m_Map.Next()))
|
136 |
|
|
{
|
137 |
|
|
SolutionInfo *pInfo = (SolutionInfo*) node->Data();
|
138 |
|
|
#endif
|
139 |
|
|
free(pInfo);
|
140 |
|
|
}
|
141 |
|
|
m_Map.Clear();
|
142 |
|
|
|
143 |
|
|
// OK to change values again
|
144 |
|
|
wxGetApp().UnlockValues();
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
void ecResolveConflictsDialog::CreateControls(wxWindow* parent)
|
148 |
|
|
{
|
149 |
|
|
// Create custom windows first
|
150 |
|
|
m_conflictsCtrl = new ecConflictListCtrl(parent, ecID_CONFLICTS_CONFLICTS, wxDefaultPosition, wxSize(470, 110), wxLC_REPORT|wxCLIP_CHILDREN|wxSUNKEN_BORDER);
|
151 |
|
|
m_solutionsCtrl = new ecSolutionListCtrl(parent, ecID_CONFLICTS_SOLUTIONS, wxDefaultPosition, wxSize(470, 110), wxLC_REPORT|wxCLIP_CHILDREN|wxSUNKEN_BORDER);
|
152 |
|
|
|
153 |
|
|
wxSizer *item0 = new wxBoxSizer( wxVERTICAL );
|
154 |
|
|
|
155 |
|
|
wxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
|
156 |
|
|
|
157 |
|
|
wxButton *item2 = new wxButton( parent, ecID_CONFLICTS_CONTINUE, _("&Continue"), wxDefaultPosition, wxDefaultSize, 0 );
|
158 |
|
|
item2->SetDefault();
|
159 |
|
|
item1->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
|
160 |
|
|
|
161 |
|
|
wxButton *item3 = new wxButton( parent, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
|
162 |
|
|
item1->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
|
163 |
|
|
|
164 |
|
|
item0->Add( item1, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
165 |
|
|
|
166 |
|
|
wxWindow *item4 = parent->FindWindow( ecID_CONFLICTS_CONFLICTS );
|
167 |
|
|
wxASSERT( item4 );
|
168 |
|
|
item0->Add( item4, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
169 |
|
|
|
170 |
|
|
wxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
|
171 |
|
|
|
172 |
|
|
wxStaticText *item6 = new wxStaticText( parent, ecID_CONFLICTS_MSG, _("Proposed Solutions:"), wxDefaultPosition, wxSize(250,-1), 0 );
|
173 |
|
|
item5->Add( item6, 0, wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALL, 0 );
|
174 |
|
|
|
175 |
|
|
item5->Add( 30, 20, 1, wxALIGN_CENTRE|wxALL, 0 );
|
176 |
|
|
|
177 |
|
|
wxButton *item7 = new wxButton( parent, ecID_CONFLICTS_NONE, _("&None"), wxDefaultPosition, wxDefaultSize, 0 );
|
178 |
|
|
item5->Add( item7, 0, wxALIGN_CENTRE|wxALL, 5 );
|
179 |
|
|
|
180 |
|
|
wxButton *item8 = new wxButton( parent, ecID_CONFLICTS_ALL, _("&All"), wxDefaultPosition, wxDefaultSize, 0 );
|
181 |
|
|
item5->Add( item8, 0, wxALIGN_CENTRE|wxALL, 5 );
|
182 |
|
|
|
183 |
|
|
item0->Add( item5, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
184 |
|
|
|
185 |
|
|
wxWindow *item9 = parent->FindWindow( ecID_CONFLICTS_SOLUTIONS );
|
186 |
|
|
wxASSERT( item9 );
|
187 |
|
|
item0->Add( item9, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
188 |
|
|
|
189 |
|
|
#ifdef __WXGTK__
|
190 |
|
|
wxButton *contextButton = new wxContextHelpButton( parent );
|
191 |
|
|
item1->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
|
192 |
|
|
#endif
|
193 |
|
|
|
194 |
|
|
parent->SetAutoLayout( TRUE );
|
195 |
|
|
parent->SetSizer( item0 );
|
196 |
|
|
|
197 |
|
|
// N.B. I find I have to call Layout, then Fit, to make this
|
198 |
|
|
// work.
|
199 |
|
|
parent->Layout();
|
200 |
|
|
item0->Fit( parent );
|
201 |
|
|
item0->SetSizeHints( parent );
|
202 |
|
|
|
203 |
|
|
// Add context-sensitive help text
|
204 |
|
|
parent->FindWindow( ecID_CONFLICTS_CONFLICTS )->SetHelpText(_("Displays the set of conflicts for which the fixes are offered."));
|
205 |
|
|
parent->FindWindow( ecID_CONFLICTS_SOLUTIONS )->SetHelpText(_("Displays fixes for the currently selected conflict. Use the checkboxes to enable or disable each fix."));
|
206 |
|
|
parent->FindWindow( ecID_CONFLICTS_CONTINUE )->SetHelpText(_("Continues the current transaction, applying the selected solutions."));
|
207 |
|
|
parent->FindWindow( wxID_CANCEL )->SetHelpText(_("Cancels the current transaction, without applying any solutions."));
|
208 |
|
|
parent->FindWindow( ecID_CONFLICTS_NONE )->SetHelpText(_("Resets all fix checkboxes to the unchecked state."));
|
209 |
|
|
parent->FindWindow( ecID_CONFLICTS_ALL )->SetHelpText(_("Resets all fix checkboxes to the checked state."));
|
210 |
|
|
|
211 |
|
|
#if __WXGTK__
|
212 |
|
|
parent->FindWindow( wxID_CONTEXT_HELP )->SetHelpText(_("Invokes context-sensitive help for the clicked-on window."));
|
213 |
|
|
#endif
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
void ecResolveConflictsDialog::OnInitDialog(wxInitDialogEvent& event)
|
217 |
|
|
{
|
218 |
|
|
wxDialog::OnInitDialog(event);
|
219 |
|
|
|
220 |
|
|
// Select the first item and fill the solution set
|
221 |
|
|
m_conflictsCtrl->AddConflicts(m_conflicts);
|
222 |
|
|
|
223 |
|
|
#if wxCHECK_VERSION(2, 6, 0)
|
224 |
|
|
if (m_parConflictsOfInterest && m_parConflictsOfInterest->GetCount()>0)
|
225 |
|
|
#else
|
226 |
|
|
if (m_parConflictsOfInterest && m_parConflictsOfInterest->Number()>0)
|
227 |
|
|
#endif
|
228 |
|
|
{
|
229 |
|
|
wxList &arConflictsOfInterest = *m_parConflictsOfInterest;
|
230 |
|
|
int i, j;
|
231 |
|
|
for ( i = m_conflictsCtrl->GetItemCount() - 1; i >= 0; --i )
|
232 |
|
|
{
|
233 |
|
|
#if wxCHECK_VERSION(2, 6, 0)
|
234 |
|
|
for ( j = arConflictsOfInterest.GetCount() - 1; j>=0; --j )
|
235 |
|
|
#else
|
236 |
|
|
for ( j = arConflictsOfInterest.Number() - 1; j>=0; --j )
|
237 |
|
|
#endif
|
238 |
|
|
{
|
239 |
|
|
CdlConflict conflict = (CdlConflict)m_conflictsCtrl->GetItemData(i);
|
240 |
|
|
if ( ((CdlConflict) arConflictsOfInterest[j]) == conflict )
|
241 |
|
|
{
|
242 |
|
|
m_conflictsCtrl->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
243 |
|
|
m_conflictsCtrl->EnsureVisible(i);
|
244 |
|
|
arConflictsOfInterest.DeleteObject(arConflictsOfInterest[j]);
|
245 |
|
|
break;
|
246 |
|
|
}
|
247 |
|
|
}
|
248 |
|
|
}
|
249 |
|
|
} else
|
250 |
|
|
{
|
251 |
|
|
for ( int i = m_conflictsCtrl->GetItemCount()-1; i>=0; --i )
|
252 |
|
|
{
|
253 |
|
|
m_conflictsCtrl->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
m_conflictsCtrl->SetFocus();
|
257 |
|
|
}
|
258 |
|
|
|
259 |
|
|
void ecResolveConflictsDialog::OnContinue(wxCommandEvent& event)
|
260 |
|
|
{
|
261 |
|
|
// Ensure we have the current conflict check array
|
262 |
|
|
int i;
|
263 |
|
|
for (i = 0; i < m_conflictsCtrl->GetItemCount(); i++)
|
264 |
|
|
{
|
265 |
|
|
if (m_conflictsCtrl->GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED)
|
266 |
|
|
RemoveConflictSolutions((CdlConflict) m_conflictsCtrl->GetItemData(i));
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
// Dismiss the window
|
270 |
|
|
EndModal(wxID_OK);
|
271 |
|
|
|
272 |
|
|
std::list<CdlConflict>::const_iterator conf_i;
|
273 |
|
|
|
274 |
|
|
for (conf_i= m_conflicts.begin (); conf_i != m_conflicts.end (); conf_i++) // for each conflict
|
275 |
|
|
{
|
276 |
|
|
CdlConflict conflict=*conf_i;
|
277 |
|
|
//int nSolutions=conflict->get_solution().size();
|
278 |
|
|
SolutionInfo &info=Info(conflict);
|
279 |
|
|
int nIndex=0;
|
280 |
|
|
const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution();
|
281 |
|
|
for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin();soln_i != Solution.end(); soln_i++) {
|
282 |
|
|
if(SolutionInfo::CHECKED==info.arItem[nIndex++]){
|
283 |
|
|
CdlValuable valuable = soln_i->first;
|
284 |
|
|
CdlValue value=soln_i->second;
|
285 |
|
|
CdlValueFlavor flavor = valuable->get_flavor();
|
286 |
|
|
const wxString strName(valuable->get_name().c_str());
|
287 |
|
|
const wxString strValue(value.get_value().c_str());
|
288 |
|
|
bool rc = TRUE;
|
289 |
|
|
wxString str;
|
290 |
|
|
try
|
291 |
|
|
{
|
292 |
|
|
switch(flavor)
|
293 |
|
|
{
|
294 |
|
|
case CdlValueFlavor_None :
|
295 |
|
|
str = wxT("set CdlValueFlavor_None");
|
296 |
|
|
rc = FALSE;
|
297 |
|
|
break;
|
298 |
|
|
case CdlValueFlavor_Bool :
|
299 |
|
|
str.Printf(_("%s %s\n"), (const wxChar*) (value.is_enabled()?_("disable"):_("enable")), (const wxChar*) strName);
|
300 |
|
|
valuable->set_enabled (m_Transaction, value.is_enabled(), CdlValueSource_User);
|
301 |
|
|
break;
|
302 |
|
|
case CdlValueFlavor_BoolData :
|
303 |
|
|
{
|
304 |
|
|
bool bEnabled=value.is_enabled();
|
305 |
|
|
str.Printf(_("%s %s and set value to %s\n"), (const wxChar*) (bEnabled? _("disable"):_("enable")), (const wxChar*) strName, (const wxChar*) strValue);
|
306 |
|
|
// Surely this is wrong - we don't want to set the same value, we want to
|
307 |
|
|
// set a NEW value.
|
308 |
|
|
// CdlSimpleValue simple_value = valuable->get_simple_value ();
|
309 |
|
|
//valuable->set_enabled_and_value (m_Transaction, bEnabled, simple_value, CdlValueSource_User);
|
310 |
|
|
valuable->set_enabled_and_value (m_Transaction, bEnabled, ecUtils::UnicodeToStdStr (strValue), CdlValueSource_User);
|
311 |
|
|
}
|
312 |
|
|
break;
|
313 |
|
|
case CdlValueFlavor_Data :
|
314 |
|
|
str.Printf(_("set %s to %s\n"), (const wxChar*) strName, (const wxChar*) strValue);
|
315 |
|
|
valuable->set_value (m_Transaction, ecUtils::UnicodeToStdStr (strValue), CdlValueSource_User);
|
316 |
|
|
break;
|
317 |
|
|
}
|
318 |
|
|
}
|
319 |
|
|
catch(...)
|
320 |
|
|
{
|
321 |
|
|
rc = FALSE;
|
322 |
|
|
}
|
323 |
|
|
if(rc)
|
324 |
|
|
{
|
325 |
|
|
wxGetApp().GetConfigToolDoc()->Modify(TRUE);
|
326 |
|
|
} else
|
327 |
|
|
{
|
328 |
|
|
wxString msg;
|
329 |
|
|
msg.Printf(_("Failed to %s\n"), (const wxChar*) str);
|
330 |
|
|
wxMessageBox(msg, wxGetApp().GetSettings().GetAppName(), wxICON_EXCLAMATION|wxOK);
|
331 |
|
|
}
|
332 |
|
|
}
|
333 |
|
|
}
|
334 |
|
|
}
|
335 |
|
|
}
|
336 |
|
|
|
337 |
|
|
void ecResolveConflictsDialog::OnAll(wxCommandEvent& event)
|
338 |
|
|
{
|
339 |
|
|
SetAll(TRUE);
|
340 |
|
|
}
|
341 |
|
|
|
342 |
|
|
void ecResolveConflictsDialog::OnNone(wxCommandEvent& event)
|
343 |
|
|
{
|
344 |
|
|
SetAll(FALSE);
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
void ecResolveConflictsDialog::SetAll(bool bOnOff)
|
348 |
|
|
{
|
349 |
|
|
long i;
|
350 |
|
|
for ( i = m_solutionsCtrl->GetItemCount()-1; i >= 0; --i)
|
351 |
|
|
{
|
352 |
|
|
m_solutionsCtrl->SetChecked(i, bOnOff);
|
353 |
|
|
}
|
354 |
|
|
}
|
355 |
|
|
|
356 |
|
|
// Update All button
|
357 |
|
|
void ecResolveConflictsDialog::OnUpdateAll(wxUpdateUIEvent& event)
|
358 |
|
|
{
|
359 |
|
|
if (!m_solutionsCtrl)
|
360 |
|
|
return;
|
361 |
|
|
|
362 |
|
|
int nCheckCount=0;
|
363 |
|
|
int nItemCount = m_solutionsCtrl->GetItemCount();
|
364 |
|
|
int i;
|
365 |
|
|
for (i=nItemCount-1;i>=0;--i)
|
366 |
|
|
{
|
367 |
|
|
nCheckCount+=m_solutionsCtrl->IsChecked(i);
|
368 |
|
|
}
|
369 |
|
|
event.Enable(nItemCount>0 && nCheckCount<nItemCount);
|
370 |
|
|
}
|
371 |
|
|
|
372 |
|
|
// Update None button
|
373 |
|
|
void ecResolveConflictsDialog::OnUpdateNone(wxUpdateUIEvent& event)
|
374 |
|
|
{
|
375 |
|
|
if (!m_solutionsCtrl)
|
376 |
|
|
return;
|
377 |
|
|
|
378 |
|
|
int nCheckCount=0;
|
379 |
|
|
int nItemCount=m_solutionsCtrl->GetItemCount();
|
380 |
|
|
int i;
|
381 |
|
|
for (i=nItemCount-1;i>=0;--i){
|
382 |
|
|
nCheckCount+=m_solutionsCtrl->IsChecked(i);
|
383 |
|
|
}
|
384 |
|
|
event.Enable(nItemCount>0 && nCheckCount>0);
|
385 |
|
|
}
|
386 |
|
|
|
387 |
|
|
// Currently there is no 'locate' button so this is not called from anywhere.
|
388 |
|
|
// However, the intention in the MFC configtool must have been to use it,
|
389 |
|
|
// although it wasn't in the Resolve Conflicts dialog.
|
390 |
|
|
void ecResolveConflictsDialog::OnLocate()
|
391 |
|
|
{
|
392 |
|
|
ecConfigItem *pItem = m_conflictsCtrl->AssociatedItem(m_nContextItem, m_nContextRow);
|
393 |
|
|
if (pItem) {
|
394 |
|
|
if (wxGetApp().GetTreeCtrl())
|
395 |
|
|
wxGetApp().GetTreeCtrl()->SelectItem(pItem->GetTreeItem());
|
396 |
|
|
}
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
void ecResolveConflictsDialog::RemoveConflictSolutions(CdlConflict conflict)
|
400 |
|
|
{
|
401 |
|
|
SolutionInfo &info=Info(conflict);
|
402 |
|
|
int i, j, k;
|
403 |
|
|
for ( i = 0; i < info.nCount; i++ )
|
404 |
|
|
{
|
405 |
|
|
int nItem=info.arItem[i];
|
406 |
|
|
wxASSERT(nItem>=0);
|
407 |
|
|
info.arItem[i] = (m_solutionsCtrl->IsChecked(nItem) ? SolutionInfo::CHECKED:SolutionInfo::UNCHECKED);
|
408 |
|
|
int nRefs = m_solutionsCtrl->GetItemData(nItem);
|
409 |
|
|
if (1 == nRefs)
|
410 |
|
|
{
|
411 |
|
|
m_solutionsCtrl->DeleteItem(nItem);
|
412 |
|
|
for ( k = 0; k < m_conflictsCtrl->GetItemCount(); k++ )
|
413 |
|
|
{
|
414 |
|
|
SolutionInfo &info2 = Info((CdlConflict)m_conflictsCtrl->GetItemData(k));
|
415 |
|
|
for ( j = 0; j < info2.nCount; j++)
|
416 |
|
|
{
|
417 |
|
|
if (info2.arItem[j] > nItem)
|
418 |
|
|
{
|
419 |
|
|
info2.arItem[j] --;
|
420 |
|
|
}
|
421 |
|
|
}
|
422 |
|
|
}
|
423 |
|
|
} else
|
424 |
|
|
{
|
425 |
|
|
m_solutionsCtrl->SetItemData(nItem, nRefs-1);
|
426 |
|
|
}
|
427 |
|
|
}
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
void ecResolveConflictsDialog::AddConflictSolutions(CdlConflict conflict)
|
431 |
|
|
{
|
432 |
|
|
// SolutionInfo allows each conflict to know which solutions have been found for it
|
433 |
|
|
SolutionInfo &info=Info(conflict);
|
434 |
|
|
|
435 |
|
|
const std::vector<std::pair<CdlValuable, CdlValue> >&Solution=conflict->get_solution();
|
436 |
|
|
|
437 |
|
|
int i=0;
|
438 |
|
|
for (std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator soln_i = Solution.begin();
|
439 |
|
|
soln_i != Solution.end(); soln_i++)
|
440 |
|
|
{
|
441 |
|
|
CdlValuable valuable = soln_i->first;
|
442 |
|
|
CdlValue value = soln_i->second;
|
443 |
|
|
CdlValueFlavor flavor = valuable->get_flavor();
|
444 |
|
|
|
445 |
|
|
wxString strValue;
|
446 |
|
|
switch(flavor)
|
447 |
|
|
{
|
448 |
|
|
case CdlValueFlavor_None :
|
449 |
|
|
break;
|
450 |
|
|
case CdlValueFlavor_Bool :
|
451 |
|
|
strValue = value.is_enabled() ? _("Enabled") : _("Disabled");
|
452 |
|
|
break;
|
453 |
|
|
case CdlValueFlavor_BoolData :
|
454 |
|
|
strValue.Printf(wxT("%s, %s"), (const wxChar*) (value.is_enabled() ? _("Enabled") : _("Disabled")), (const wxChar*) value.get_value().c_str());
|
455 |
|
|
break;
|
456 |
|
|
case CdlValueFlavor_Data :
|
457 |
|
|
strValue = value.get_value().c_str();
|
458 |
|
|
break;
|
459 |
|
|
}
|
460 |
|
|
|
461 |
|
|
const wxString strName(soln_i->first->get_name().c_str());
|
462 |
|
|
|
463 |
|
|
long nIndex = m_solutionsCtrl->FindItem(0, strName);
|
464 |
|
|
wxListItem listItem;
|
465 |
|
|
listItem.m_mask = wxLIST_MASK_TEXT;
|
466 |
|
|
listItem.m_itemId = nIndex;
|
467 |
|
|
listItem.m_col = 1;
|
468 |
|
|
if (nIndex != -1)
|
469 |
|
|
m_solutionsCtrl->GetItem(listItem);
|
470 |
|
|
|
471 |
|
|
if (-1 == nIndex || strValue != listItem.m_text)
|
472 |
|
|
{
|
473 |
|
|
// We don't have an existing solution that matches this one
|
474 |
|
|
nIndex = m_solutionsCtrl->GetItemCount();
|
475 |
|
|
m_solutionsCtrl->InsertItem(nIndex, strName);
|
476 |
|
|
m_solutionsCtrl->SetItemData(nIndex, 1);
|
477 |
|
|
m_solutionsCtrl->SetItem(nIndex, 1, strValue);
|
478 |
|
|
|
479 |
|
|
wxASSERT(info.arItem[i]<0);
|
480 |
|
|
|
481 |
|
|
m_solutionsCtrl->SetChecked(nIndex, SolutionInfo::CHECKED==info.arItem[i]);
|
482 |
|
|
} else {
|
483 |
|
|
// We do - to avoid duplicates, increment the "ref count"
|
484 |
|
|
m_solutionsCtrl->SetItemData(nIndex, m_solutionsCtrl->GetItemData(nIndex)+1);
|
485 |
|
|
}
|
486 |
|
|
info.arItem[i++]=nIndex;
|
487 |
|
|
|
488 |
|
|
}
|
489 |
|
|
wxStaticText* staticCtrl = (wxStaticText*) FindWindow(ecID_CONFLICTS_MSG);
|
490 |
|
|
|
491 |
|
|
if(0==i){
|
492 |
|
|
staticCtrl->SetLabel(_("No solution is available for this conflict"));
|
493 |
|
|
m_solutionsCtrl->Show(FALSE);
|
494 |
|
|
} else {
|
495 |
|
|
staticCtrl->SetLabel(_("Proposed solution:"));
|
496 |
|
|
m_solutionsCtrl->Show(TRUE);
|
497 |
|
|
// TODO (if necessary)
|
498 |
|
|
#if 0
|
499 |
|
|
m_List.SetColumnWidth(0,LVSCW_AUTOSIZE);
|
500 |
|
|
CRect rect;
|
501 |
|
|
m_List.GetClientRect(rect);
|
502 |
|
|
m_List.SetColumnWidth(1,rect.Width()-m_List.GetColumnWidth(0));
|
503 |
|
|
#endif
|
504 |
|
|
}
|
505 |
|
|
}
|
506 |
|
|
|
507 |
|
|
ecResolveConflictsDialog::SolutionInfo & ecResolveConflictsDialog::Info(const CdlConflict conflict)
|
508 |
|
|
{
|
509 |
|
|
SolutionInfo *pInfo = (SolutionInfo*) m_Map.Get((long) conflict);
|
510 |
|
|
return * pInfo;
|
511 |
|
|
}
|
512 |
|
|
|
513 |
|
|
void ecResolveConflictsDialog::OnConflictSelected(wxListEvent& event)
|
514 |
|
|
{
|
515 |
|
|
CdlConflict conflict=(CdlConflict) m_conflictsCtrl->GetItemData(event.GetIndex());
|
516 |
|
|
|
517 |
|
|
if (1 == m_solutionsCtrl->GetSelectedItemCount())
|
518 |
|
|
{
|
519 |
|
|
// TODO ??
|
520 |
|
|
// GetDlgItem(IDC_STATIC1)->ShowWindow(SW_HIDE);
|
521 |
|
|
m_solutionsCtrl->Show(TRUE);
|
522 |
|
|
}
|
523 |
|
|
AddConflictSolutions(conflict);
|
524 |
|
|
}
|
525 |
|
|
|
526 |
|
|
void ecResolveConflictsDialog::OnConflictDeselected(wxListEvent& event)
|
527 |
|
|
{
|
528 |
|
|
CdlConflict conflict=(CdlConflict) m_conflictsCtrl->GetItemData(event.GetIndex());
|
529 |
|
|
|
530 |
|
|
RemoveConflictSolutions(conflict);
|
531 |
|
|
}
|
532 |
|
|
|
533 |
|
|
|
534 |
|
|
#if 0
|
535 |
|
|
// TODO?
|
536 |
|
|
|
537 |
|
|
// We need to use this because the OnItemChanged handler successive receives "not selected" followed by "selected"
|
538 |
|
|
// notifications. The result is that the "Select one or more conflicts to display available solutions" message
|
539 |
|
|
// would be seen briefly when clicking from one selection to another.
|
540 |
|
|
BOOL ecResolveConflictsDialog::OnClick(UINT,LPNMLISTVIEW pnmv, LRESULT* pResult)
|
541 |
|
|
{
|
542 |
|
|
if(-1==pnmv->iItem && 0==m_List.GetSelectedCount()){
|
543 |
|
|
SetDlgItemText(IDC_STATIC1,_T("Select one or more conflicts to display available solutions"));
|
544 |
|
|
m_List.ShowWindow(SW_HIDE);
|
545 |
|
|
GetDlgItem(IDC_STATIC1)->ShowWindow(SW_SHOW);
|
546 |
|
|
GetDlgItem(IDC_RESET)->EnableWindow(false);
|
547 |
|
|
GetDlgItem(IDC_CONFLICTS_NONE)->EnableWindow(false);
|
548 |
|
|
}
|
549 |
|
|
*pResult = 0;
|
550 |
|
|
return false; // not handled
|
551 |
|
|
}
|
552 |
|
|
|
553 |
|
|
// TODO
|
554 |
|
|
BOOL ecResolveConflictsDialog::OnRClick(UINT, LPNMITEMACTIVATE pnmv, LRESULT* pResult)
|
555 |
|
|
{
|
556 |
|
|
DWORD dwPos=GetMessagePos();
|
557 |
|
|
CPoint pt(GET_X_LPARAM(dwPos),GET_Y_LPARAM(dwPos));
|
558 |
|
|
m_nContextItem=pnmv->iItem;
|
559 |
|
|
m_nContextRow=pnmv->iSubItem;
|
560 |
|
|
if(-1!=m_nContextItem){
|
561 |
|
|
//m_RulesList.SetItemState(m_nContextItem,LVIS_SELECTED,LVIS_SELECTED);
|
562 |
|
|
Menu menu;
|
563 |
|
|
menu.CreatePopupMenu();
|
564 |
|
|
menu.AppendMenu(1==m_RulesList.GetSelectedCount() && m_RulesList.AssociatedItem(m_nContextItem,m_nContextRow)?MF_STRING:(MF_STRING|MF_GRAYED),ID_LOCATE,_T("&Locate"));
|
565 |
|
|
#ifndef PLUGIN
|
566 |
|
|
SuppressNextContextMenuMessage();
|
567 |
|
|
#endif
|
568 |
|
|
menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pt.x,pt.y,this);
|
569 |
|
|
}
|
570 |
|
|
|
571 |
|
|
*pResult = 0;
|
572 |
|
|
return TRUE; // handled
|
573 |
|
|
}
|
574 |
|
|
|
575 |
|
|
#endif
|
576 |
|
|
|