1 /* 2 * "GEDKeeper", the personal genealogical database editor. 3 * Copyright (C) 2009-2018 by Sergey V. Zhdanovskih. 4 * 5 * This file is part of "GEDKeeper". 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 using System.Collections.Generic; 22 using BSLib; 23 using GDModel; 24 using GKCore.MVP; 25 using GKCore.MVP.Views; 26 using GKCore.Tools; 27 28 namespace GKCore.Controllers 29 { 30 /// <summary> 31 /// 32 /// </summary> 33 public class PlacesManagerController : DialogController<IPlacesManagerDlg> 34 { 35 private readonly StringList fPlaces; 36 PlacesManagerController(IPlacesManagerDlg view)37 public PlacesManagerController(IPlacesManagerDlg view) : base(view) 38 { 39 fPlaces = new StringList(); 40 fPlaces.Sorted = true; 41 } 42 UpdateView()43 public override void UpdateView() 44 { 45 } 46 Clear()47 public void Clear() 48 { 49 TreeTools.SearchPlaces_Clear(fPlaces); 50 fPlaces.Dispose(); 51 } 52 CheckPlaces()53 public void CheckPlaces() 54 { 55 fView.PlacesList.BeginUpdate(); 56 try { 57 TreeTools.SearchPlaces(fBase.Context.Tree, fPlaces, AppHost.Progress); 58 59 fView.PlacesList.ClearItems(); 60 61 int num4 = fPlaces.Count; 62 for (int i = 0; i < num4; i++) { 63 PlaceObj placeObj = (PlaceObj)fPlaces.GetObject(i); 64 65 fView.PlacesList.AddItem(placeObj, new object[] { fPlaces[i], placeObj.Facts.Count }); 66 } 67 } finally { 68 fView.PlacesList.EndUpdate(); 69 } 70 } 71 CreateLocationRecord(IList<object> placesList)72 public void CreateLocationRecord(IList<object> placesList) 73 { 74 PlaceObj pObj = placesList.Count > 0 ? (PlaceObj) placesList[0] : null; 75 if (pObj == null) return; 76 77 if (pObj.Name.IndexOf("[*]") == 0) { 78 AppHost.StdDialogs.ShowMessage(LangMan.LS(LSID.LSID_PlaceAlreadyInBook)); 79 } else { 80 GDMLocationRecord locRec = fBase.Context.SelectRecord(GDMRecordType.rtLocation, new object[] { pObj.Name }) as GDMLocationRecord; 81 if (locRec == null) return; 82 83 for (var pi = 0; pi < placesList.Count; pi++) { 84 PlaceObj place = (PlaceObj) placesList[pi]; 85 int num = place.Facts.Count; 86 for (int i = 0; i < num; i++) { 87 GDMCustomEvent evt = place.Facts[i]; 88 evt.Place.StringValue = locRec.LocationName; 89 evt.Place.Location.XRef = locRec.XRef; 90 } 91 } 92 93 CheckPlaces(); 94 fBase.RefreshLists(false); 95 } 96 } 97 } 98 } 99