// ############ PRIVATE void SaveRecent(string storage, string f) { if (Storage.Load(storage).Length == 0) { Storage.Save(storage, f); } else { List <string> lst = new List <string>(Storage.Load(storage).Split('|')); if (lst.Contains(f)) { lst.RemoveAt(lst.IndexOf(f)); } lst.Add(f); if (lst.Count > 5) { lst.RemoveAt(0); } string s = string.Empty; lst.ForEach(i => s += i + '|'); Storage.Save(storage, s.Substring(0, s.Length - 1)); } }
void LoadRecent(string storage, string menuitem) { string ss = Storage.Load(storage); MenuItem menu = (FindName(menuitem) as MenuItem); StackPanel mm = null; if (filez.Items.Count > 0) { mm = ((filez.Items[0] as TabItem).Content as XapEditor.controls.Startpage).FindName(string.Format("metro_{0}", menuitem)) as StackPanel; mm.Children.Clear(); } menu.Items.Clear(); menu.IsEnabled = false; if (ss.Length > 0) { List <string> lst = new List <string>(ss.Split('|')); if (lst.Count > 0) { for (int a = lst.Count - 1; a >= 0; a--) { MenuItem mi = new MenuItem() { Header = Path.GetFileName(lst[a]), ToolTip = lst[a], Tag = lst[a] }; mi.Click += delegate(object se, RoutedEventArgs e) { OpenFile((se as MenuItem).Tag.ToString()); }; mi.IsEnabled = System.IO.File.Exists(lst[a]); menu.Items.Add(mi); bool isx = menuitem.Contains("xap"); XapEditor.controls.MetroTile mt = new controls.MetroTile() { Icon = (isx ? "box" : "file"), Text = mi.Header.ToString(), Tag = mi.Tag }; mt.BackgroundBrush = new SolidColorBrush(!isx ? Color.FromArgb(102, 100, 140, 255) : Color.FromArgb(102, 190, 255, 20)); mt.txt.FontSize = 18; mt.Click += delegate(object s, RoutedEventArgs e) { OpenFile((s as XapEditor.controls.MetroTile).Tag.ToString()); }; if (mm != null) { mm.Children.Add(mt); } } MenuItem ci = new MenuItem() { Header = "Clear List", Tag = menuitem, Icon = new System.Windows.Controls.Image { Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("icons/icon_del.png", UriKind.Relative)) } }; ci.Click += delegate(object se, RoutedEventArgs ev) { Storage.Save(storage, string.Empty); LoadRecent(storage, (se as MenuItem).Tag.ToString()); }; menu.Items.Add(new Separator()); menu.Items.Add(ci); menu.IsEnabled = true; } } else { if (mm != null) { mm.Children.Add(new TextBlock() { Text = "The list is empty", FontStyle = FontStyles.Italic, Margin = new Thickness(4, 0, 4, 0), Foreground = new SolidColorBrush(Color.FromArgb(102, 0, 0, 0)) }); } } }