1 /*
2 	This file is part of Code Snippets, a plugin for Code::Blocks
3 	Copyright (C) 2006 Arto Jonsson
4 	Copyright (C) 2007 Pecan Heber
5 
6 	This program is free software; you can redistribute it and/or
7 	modify it under the terms of the GNU General Public License
8 	as published by the Free Software Foundation; either version 2
9 	of the License, or (at your option) any later version.
10 
11 	This program is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 	GNU 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 Free Software
18 	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20 // RCS-ID: $Id: snippetitemdata.cpp 10362 2015-07-26 08:13:33Z jenslody $
21 
22 #ifdef WX_PRECOMP
23     #include "wx_pch.h"
24 #else
25 #endif
26 
27 #include "snippetitemdata.h"
28 #include "snippetsconfig.h"
29 #include "codesnippetswindow.h"
30 
31 // ----------------------------------------------------------------------------
32 // statics
33 // ----------------------------------------------------------------------------
34 long     SnippetTreeItemData::m_HighestSnippetID = 0;
35 unsigned SnippetTreeItemData::m_itemsChangedCount = 0;
36 
37 // ----------------------------------------------------------------------------
SnippetTreeItemData(SnippetItemType type,SnippetItemID oldID)38 SnippetTreeItemData::SnippetTreeItemData(SnippetItemType type, SnippetItemID oldID)
39 // ----------------------------------------------------------------------------
40     : m_Type(type), m_Snippet(wxEmptyString), m_ID(oldID)
41 {
42     InitializeItem(oldID);
43 }
44 // ----------------------------------------------------------------------------
SnippetTreeItemData(SnippetItemType type,wxString snippet,SnippetItemID oldID)45 SnippetTreeItemData::SnippetTreeItemData(SnippetItemType type, wxString snippet, SnippetItemID oldID)
46 // ---------------------------------------------------------------------------
47     : m_Type(type), m_Snippet(snippet), m_ID(oldID)
48 {
49     InitializeItem(oldID);
50 }
51 // ----------------------------------------------------------------------------
~SnippetTreeItemData()52 SnippetTreeItemData::~SnippetTreeItemData()
53 // ----------------------------------------------------------------------------
54 {
55 	//dtor
56 }
57 // ----------------------------------------------------------------------------
InitializeItem(SnippetItemID oldID)58 void SnippetTreeItemData::InitializeItem(SnippetItemID oldID)
59 // ----------------------------------------------------------------------------
60 {
61     //m_ID already set by ctor init m_ID(oldID)
62     if ( 0 == oldID )
63         m_ID = GetNewID();
64 
65     // if ID is less than highest, must be merging another .xml
66     if ( m_ID < m_HighestSnippetID )
67         if ( GetConfig()->GetSnippetsWindow()->IsAppendingFile() )
68             m_ID = GetNewID();
69 
70     if ( oldID not_eq m_ID )
71         m_itemsChangedCount += 1;
72 
73     // if ID is greater than highest, set to highest
74     UpdateHighestSnippetID(m_ID);
75 }
76 
77