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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// file name : AddFunctionsImpDlg.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 "AddFunctionsImpDlg.h"
#include "ctags_manager.h"
#include "windowattrmanager.h"
class MyAddFunctionsModel : public AddFunctionsModel
{
public:
MyAddFunctionsModel() {}
virtual ~MyAddFunctionsModel() {}
virtual bool GetAttr(const wxDataViewItem &item,
unsigned int col,
wxDataViewItemAttr & attr) const {
if ( col == 1 ) {
wxVariant v;
GetValue(v, item, 0);
if ( !v.GetBool() ) {
attr.SetColour( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT ) );
attr.SetBold(false);
} else {
attr.SetBold(true);
}
return true;
} else {
return false;
}
}
};
AddFunctionsImpDlg::AddFunctionsImpDlg(wxWindow* parent, const TagEntryPtrVector_t &tags, const wxString &targetFile)
: AddFunctionsImplBaseDlg(parent)
{
unsigned int colCount = m_dataviewModel->GetColCount();
m_dataviewModel = new MyAddFunctionsModel();
m_dataviewModel->SetColCount( colCount );
m_dataview->AssociateModel( m_dataviewModel.get() );
m_tags.insert(m_tags.end(), tags.begin(), tags.end());
for(size_t i=0; i<m_tags.size(); ++i) {
wxVector<wxVariant> cols;
cols.push_back(true);
cols.push_back( m_tags.at(i)->GetDisplayName() );
// keep the implementation as the client data
wxString body;
TagEntryPtr tag = m_tags.at(i);
tag->SetSignature( TagsManagerST::Get()->NormalizeFunctionSig( tag->GetSignature(), Normalize_Func_Name ) );
body << TagsManagerST::Get()->FormatFunction(tag, FunctionFormat_Impl);
body << wxT("\n");
m_dataviewModel->AppendItem( wxDataViewItem(0), cols, new wxStringClientData(body) );
}
m_filePicker->SetPath( targetFile );
SetName("AddFunctionsImpDlg");
WindowAttrManager::Load(this);
}
AddFunctionsImpDlg::~AddFunctionsImpDlg()
{
}
wxString AddFunctionsImpDlg::GetFileName() const
{
return m_filePicker->GetPath();
}
wxString AddFunctionsImpDlg::GetText() const
{
wxString text;
wxDataViewItemArray items;
m_dataviewModel->GetChildren(wxDataViewItem(0), items);
for(size_t i=0; i<items.GetCount(); ++i) {
wxVector<wxVariant> cols = m_dataviewModel->GetItemColumnsData( items.Item(i) );
if ( cols.at(0).GetBool() ) {
if ( text.IsEmpty() )
text << "\n";
// checked
wxStringClientData *cd = dynamic_cast<wxStringClientData*>(m_dataviewModel->GetClientObject( items.Item(i) ));
if ( cd ) {
text << cd->GetData();
}
}
}
if ( !text.IsEmpty() )
text.RemoveLast();
return text;
}
void AddFunctionsImpDlg::OnCheckAll(wxCommandEvent& event)
{
wxDataViewItemArray items;
m_dataviewModel->GetChildren(wxDataViewItem(0), items);
for(size_t i=0; i<items.GetCount(); ++i) {
wxVector<wxVariant> cols = m_dataviewModel->GetItemColumnsData( items.Item(i) );
cols.at(0) = true;
m_dataviewModel->UpdateItem( items.Item(i), cols );
}
}
void AddFunctionsImpDlg::OnUncheckAll(wxCommandEvent& event)
{
wxDataViewItemArray items;
m_dataviewModel->GetChildren(wxDataViewItem(0), items);
for(size_t i=0; i<items.GetCount(); ++i) {
wxVector<wxVariant> cols = m_dataviewModel->GetItemColumnsData( items.Item(i) );
cols.at(0) = false;
m_dataviewModel->UpdateItem( items.Item(i), cols );
}
}
void AddFunctionsImpDlg::OnOKUI(wxUpdateUIEvent& event)
{
wxDataViewItemArray items;
m_dataviewModel->GetChildren(wxDataViewItem(0), items);
bool atLeastOneChecked = false;
for(size_t i=0; i<items.GetCount(); ++i) {
wxVector<wxVariant> cols = m_dataviewModel->GetItemColumnsData( items.Item(i) );
if ( cols.at(0).GetBool() ) {
atLeastOneChecked = true;
break;
}
}
event.Enable( atLeastOneChecked );
}
|