Exemplo n.º 1
0
 public FileModel(MainModel parent, string file, UrlSate sate)
 {
     Parent = parent;
     _file  = file;
     _sate  = sate;
     Name   = Path.GetFileNameWithoutExtension(file);
     try
     {
         Urls = new ObservableCollection <UrlModel>(File.ReadAllLines(file)
                                                    .Distinct()
                                                    .Where(line => !string.IsNullOrEmpty(line) && !Regex.IsMatch(line, @"^\s*#"))
                                                    .Select((item, index) =>
         {
             var model = new UrlModel(this)
             {
                 Index = index + 1,
                 Value = item
             };
             return(model);
         }));
     }
     catch (Exception e)
     {
         MessageBox.Show(e.GetBaseException().Message);
         Urls = new ObservableCollection <UrlModel>();
     }
     _selectedUrl   = Urls.FirstOrDefault(url => _sate.Value == url.Value) ?? Urls.FirstOrDefault();
     _curentUrl     = _selectedUrl;
     _sate.Value    = _selectedUrl?.Value;
     BackCommand    = new DelegateCommand(Back, CanBack);
     ForwardCommand = new DelegateCommand(Forward, CanForward);
 }
Exemplo n.º 2
0
        public void Remove()
        {
            var url = SelectedUrl;

            _history.RemoveAll(u => u == url);
            _historyIndex = _history.Count;
            _curentUrl    = null;
            SelectUrl(null);
            Urls.Remove(url);
            try
            {
                var lines = File.ReadAllLines(_file).Where(line => line != url.Value);
                File.WriteAllLines(_file, lines);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.GetBaseException().Message);
            }
        }
Exemplo n.º 3
0
 public void SelectNext()
 {
     SelectedUrl = SelectedUrl.Index < Urls.Count
         ? Urls[SelectedUrl.Index]
         : null;
 }
Exemplo n.º 4
0
 private void SelectUrl(UrlModel url)
 {
     _selectedUrl = url;
     _sate.Value  = url?.Value;
     OnPropertyChanged(() => SelectedUrl);
 }