Exemple #1
0
        private void DeleteItem(object o)
        {
            Item parent = CurrentItem.Parent;
            int  idx    = -1;

            if (CurrentItem is Program)
            {
                Station station = (Station)parent;
                idx = station.Programs.IndexOf((Program)CurrentItem);
                station.Programs.Remove((Program)CurrentItem);
                if (station.Programs.Count > 0)
                {
                    idx         = Math.Min(idx, station.Programs.Count - 1);
                    CurrentItem = station.Programs[idx];
                }
                else
                {
                    CurrentItem = parent;
                }
            }
            else if (CurrentItem is Station)
            {
                Country country = (Country)parent;
                idx = country.Stations.IndexOf((Station)CurrentItem);
                country.Stations.Remove((Station)CurrentItem);
                if (country.Stations.Count > 0)
                {
                    idx         = Math.Min(idx, country.Stations.Count - 1);
                    CurrentItem = country.Stations[idx];
                }
                else
                {
                    CurrentItem = parent;
                }
            }
            else
            {
                RootItem ri = (RootItem)parent;
                idx = ri.Countries.IndexOf((Country)CurrentItem);
                ri.Countries.Remove((Country)CurrentItem);
                if (ri.Countries.Count > 0)
                {
                    idx         = Math.Min(idx, ri.Countries.Count - 1);
                    CurrentItem = ri.Countries[idx];
                }
                else
                {
                    CurrentItem = parent;
                }
            }
        }
Exemple #2
0
 private CountryModel()
 {
     RootItem = new RootItem();
     try
     {
         foreach (Country country in ReadBookmarks(Settings.ResourcePath + "bookmarks.xml"))
         {
             country.Parent = RootItem;          // needs a root
             Add(country);
         }
         RootItem.Countries = this;
     }
     catch (Exception e)
     {
         log.ErrorFormat("{0}\n{1}", e.Message, e.StackTrace);
     }
 }
Exemple #3
0
        private void AddItem(object o)
        {
            Item newItem = null;

            IsNameIsEmpty = ProgramName.Length == 0;
            if (IsNameIsEmpty)
            {
                mainViewModel.Message = new MessageModel("Field 'Name' musn't be empty!", Status.Error);
                NameFieldThickness    = 3;
                return;
            }
            else
            {
                NameFieldThickness    = 1;
                mainViewModel.Message = new MessageModel(string.Empty);
            }
            if (CurrentItem is Program && !ProgramUrl.Trim().StartsWith("http://")) // hier URL-Prüfung!!!
            {
                UrlFieldThickness     = 3;
                mainViewModel.Message = new MessageModel("Invalid URL", Status.Error);
                return;
            }
            else
            {
                UrlFieldThickness     = 1;
                mainViewModel.Message = new MessageModel(string.Empty);
            }
            Item parent = CurrentItem.Parent;

            if (CurrentItem is Program)
            {
                Station station = (Station)parent;
                newItem        = new Program(ProgramName, ProgramUrl, CurrentImage.ImagePath);
                newItem.Parent = station;
                int idx = station.Programs.IndexOf((Program)CurrentItem);
                if (idx != -1 && idx < station.Programs.Count - 1)
                {
                    station.Programs.Insert(idx + 1, (Program)newItem);
                }
                else
                {
                    station.Programs.Add((Program)newItem);
                }
            }
            else if (CurrentItem is Station)
            {
                Station station = CurrentItem as Station;
                if (station.Programs.Count > 0)
                {
                    Country country = (Country)parent;
                    newItem        = new Station(ProgramName, ProgramUrl, CurrentImage.ImagePath);
                    newItem.Parent = country;
                    int idx = country.Stations.IndexOf((Station)CurrentItem);
                    if (idx != -1 && idx < country.Stations.Count - 1)
                    {
                        country.Stations.Insert(idx + 1, (Station)newItem);
                    }
                    else
                    {
                        country.Stations.Add((Station)newItem);
                    }
                }
                else
                {
                    station        = CurrentItem as Station;
                    newItem        = new Program(ProgramName, ProgramUrl, CurrentImage.ImagePath);
                    newItem.Parent = station;
                    station.Programs.Add((Program)newItem);
                }
            }
            else
            {
                Country country = CurrentItem as Country;
                if (country.Stations.Count > 0)
                {
                    RootItem ri = (RootItem)parent;
                    Country  c  = new Country(ProgramName, ProgramUrl, CurrentImage.ImagePath);
                    c.Parent = ri;
                    int idx = ri.Countries.IndexOf((Country)CurrentItem);
                    if (idx != -1 && idx < ri.Countries.Count - 1)
                    {
                        ri.Countries.Insert(idx + 1, (Country)newItem);
                    }
                    else
                    {
                        ri.Countries.Add(c);
                    }
                }
                else
                {
                    Station station = new Station(ProgramName, ProgramUrl, CurrentImage.ImagePath);
                    station.Parent = CurrentItem;
                    country.Stations.Add(station);
                }
            }
            isNewEntryPerformed = false;
            isAddEntryPerformed = true;
            // mainViewModel.TreeChanged = true;
            CurrentItem = newItem;
        }