public ViewPage() { InitializeComponent(); DataContext = this; if (!string.IsNullOrEmpty(App.Command)) { mCurrentPage = new HistoryItem(App.Command); } else { mCurrentPage = new HistoryItem(PagesDal.DEFAULT_PAGE); } Keyboard.AddGotKeyboardFocusHandler(this, gotKeyboardFocus); Keyboard.AddLostKeyboardFocusHandler(this, lostKeyboardFocus); webBrowser1.Navigating += webBrowser1_Navigating; webBrowser1.LoadCompleted += webBrowser1_LoadCompleted; var jsinterop = new JavascriptInterop(); webBrowser1.ObjectForScripting = jsinterop; jsinterop.InvokeFromJavascript += jsinterop_InvokeFromJavascript; webBrowser1.PreviewKeyDown += webBrowser1_KeyDown; mSearchWatermarkText = textBoxSearch.Text; mSearchWatermarkBrush = textBoxSearch.Foreground; mSearchWatermarkFontStyle = textBoxSearch.FontStyle; mDal = new PagesDal(); EditCommand = new RelayCommand(() => buttonEdit_Click(null, null)); InputBindings.Add(new KeyBinding(EditCommand, new KeyGesture(Key.E, ModifierKeys.Control))); BackCommand = new RelayCommand(() => buttonBack_Click(null, null)); HomeCommand = new RelayCommand(() => buttonHome_Click(null, null)); InputBindings.Add(new KeyBinding(HomeCommand, new KeyGesture(Key.Home, ModifierKeys.Alt))); FindCommand = new RelayCommand(() => textBoxSearch.Focus()); InputBindings.Add(new KeyBinding(FindCommand, new KeyGesture(Key.OemQuestion, ModifierKeys.Control))); RecentCommand = new RelayCommand(() => recentModifications()); InputBindings.Add(new KeyBinding(RecentCommand, new KeyGesture(Key.R, ModifierKeys.Control))); initWatcher(); refresh(); restorePosition(); Loaded += (sender, e) => registerHotkey(); Unloaded += (sender, e) => unregisterHotkey(); }
private void buttonFind_Click(object sender, RoutedEventArgs e) { var query = textBoxSearch.Text; if (!string.IsNullOrEmpty(query) && query != mSearchWatermarkText) { var m = _gotoPageRegex.Match(query); if (m.Success) { //directly go to a page string pageName = m.Groups["page"].Value; setCurrentPageWithHistory(pageName); refresh(); return; } //do a normal seacrh var findResultsHtml = mDal.Find(query); setCurrentPageWithHistory(HistoryItem.CreateVirtual("Search results", findResultsHtml)); refresh(); } }
private void recentModifications() { setCurrentPageWithHistory(HistoryItem.CreateVirtual("Recent changes", mDal.RecentChanges())); refresh(); }
private void setCurrentPageWithHistory(HistoryItem newPage) { if (mHistoryStack.Count == 0 || !mHistoryStack.Peek().Equals(mCurrentPage)) { //previous page on history stack mCurrentPage.ScrollPosition = getCurrentScrollPos(); mHistoryStack.Push(mCurrentPage); } mCurrentPage = newPage; }
private void buttonBack_Click(object sender, RoutedEventArgs e) { if (mHistoryStack.Count == 0) { return; } mCurrentPage = mHistoryStack.Pop(); refresh(); }