Esempio n. 1
0
 public BrowserViewModel()
 {
     Bookmarks.GetInstance((v) => {
         BookmarkList.Value = v;
     });
     ClearURLCommand.Subscribe(() => {
         Url.Value = "";
     });
     IsBookmarked = Url.Select((url) => {
         return(BookmarkList.Value?.FindBookmark(url) != null);
     }).ToReadOnlyReactiveProperty();
 }
Esempio n. 2
0
        //private DxxUrl CreateDxxUrl() {
        //    var driver = Driver.Value;
        //    var uri = new Uri(Url.Value);
        //    return new DxxUrl(uri, driver, driver.GetNameFromUri(uri, "link"), IsMain ? "from main" : "from sub");
        //}

        private void InitializeCommands()
        {
            GoBackCommand.Subscribe(() => {
                GoBack();
            });
            GoForwardCommand.Subscribe(() => {
                GoForward();
            });
            ReloadCommand.Subscribe(() => {
                Reload();
            });
            StopCommand.Subscribe(() => {
                Stop();
            });
            BookmarkCommand.Subscribe((v) => {
                if (string.IsNullOrEmpty(v) || !v.StartsWith("http"))
                {
                    IsBookmarked.Value = false;
                    return;
                }
                if (IsBookmarked.Value)
                {
                    Bookmarks.Value.AddBookmark("", v);
                }
                else
                {
                    Bookmarks.Value.RemoveBookmark(v);
                    Url.Value = v;
                }
            });
            NavigateCommand.Subscribe((v) => {
                Navigate(v);
            });
            ClearURLCommand.Subscribe((v) => {
                Url.Value = "";
            });
            AnalyzeCommand.Subscribe((v) => {
                if (v == null)
                {
                    v = Url.Value;
                }
                var aw = new DxxAnalysisWindow(v);
                //aw.Owner = Owner;
                aw.Show();
            });
            CopyCommand.Subscribe((v) => {
                Clipboard.SetData(DataFormats.Text, v);
            });
            DownloadCommand.Subscribe(() => {
                if (IsTarget.Value || IsContainer.Value)
                {
                    DxxDriverManager.Instance.Download(Url.Value, null, "");
                }
            });
            ListingCommand.Subscribe(async() => {
                if (IsContainerList.Value)
                {
                    var uri     = new Uri(Url.Value);
                    var dxxUrl  = new DxxUrl(uri, Driver.Value, Driver.Value.GetNameFromUri(uri), "");
                    var targets = await Driver.Value.LinkExtractor.ExtractTargets(dxxUrl);
                    if (targets != null && targets.Count > 0)
                    {
                        TargetList.Value = new ObservableCollection <DxxTargetInfo>(targets);
                    }
                    else
                    {
                        TargetList.Value?.Clear();
                    }
                }
            });

            SetupDriverCommand.Subscribe(() => {
                DxxDriverManager.Instance.Setup(Driver.Value, Owner);
            });

            FrameSelectCommand.Subscribe((v) => {
                if (IsMain)
                {
                    RequestLoadInSubview.OnNext(v);
                }
                else
                {
                    Navigate(v);
                }
            });
        }