Ejemplo n.º 1
0
        private async void SearchBoxTextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                await Task.Delay(500);

                var text = (sender as TextBox).Text.Trim().ToLower();

                if (text == string.Empty)
                {
                    MenuItemsControl.ItemsSource = MenuItemsCollection;
                    GridBrowser.Visibility       = Visibility.Collapsed;
                    GridAllApps.Visibility       = Visibility.Visible;
                    return;
                }

                var found = MenuItemsCollection.Where(x => x.Name.ToLower().StartsWith(text)).AsParallel();
                if (!found.Any() && CheckBoxGoogleSearch.IsChecked == true)
                {
                    StartBrowsing("https://www.google.com/search?q=" + text);
                    return;
                }

                GridBrowser.Visibility       = Visibility.Collapsed;
                GridAllApps.Visibility       = Visibility.Visible;
                MenuItemsControl.ItemsSource = found;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
Ejemplo n.º 2
0
        private void MenuItemClicked(object sender, MouseButtonEventArgs e)
        {
            MenuItem clickedItem = new MenuItem();

            try
            {
                Border border = sender as Border;
                if (border != null)
                {
                    clickedItem = border.DataContext as MenuItem;
                    Process process = new Process();
                    if (clickedItem != null)
                    {
                        process.StartInfo.FileName        = clickedItem.Path;
                        process.StartInfo.UseShellExecute = true;
                        process.Start();
                    }
                }
            }
            catch (Exception)
            {
                var result = MessageBox.Show("File not found. Do you want to remove this item from menu?",
                                             "Error | File Not Found ", MessageBoxButton.YesNo, MessageBoxImage.Error);
                if (result == MessageBoxResult.Yes)
                {
                    MenuItemsCollection.Remove(clickedItem);
                    SaveToJsonDatabase();
                }
            }
        }
		public MenuViewModel()
		{
			this._items = new MenuItemsCollection();

			//The command is used in the Configuration example for notifying when element with children has been clicked.
			this.notifyOnClickCommand = new DelegateCommand(this.NotifyOnClickExecuted); 
		}
Ejemplo n.º 4
0
        private async Task ReadFromJsonDatabase()
        {
            try
            {
                await using FileStream openStream = File.OpenRead("Data.Json");

                JsonSerializerOptions options = new JsonSerializerOptions
                {
                    MaxDepth                 = 0,
                    IgnoreNullValues         = true,
                    IgnoreReadOnlyProperties = true
                };

                var items = await JsonSerializer.DeserializeAsync <ObservableCollection <MenuItem> >(openStream, options);

                foreach (var item in items)
                {
                    item.Icon = ToImageSource(System.Drawing.Icon.ExtractAssociatedIcon(item.Path));
                    if (item.IsFav)
                    {
                        FavItemsCollection.Add(item);
                    }

                    MenuItemsCollection.Add(item);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 5
0
 public MenuItem(String name, String url, MenuItemsCollection items)
 {
     Name = name;
     URL = "/" + url;
     _originalUrl = "/" + url;
     Items = items;
     Items.Parent = this;
 }
Ejemplo n.º 6
0
 public MenuItem(String name, String url)
 {
     Name = name;
     URL = "/" + url;
     _originalUrl = "/" + url;
     Items = new MenuItemsCollection(this);
     MenuCommand = new ActionCommand<object>(
     obj => Navigate(), obj => true);
 }
Ejemplo n.º 7
0
        public MenuViewModel(IMenuRegistry menuRegistry, IEventAggregator eventAggregator, IUserSession userSession)
        {
            _menuRegistry    = menuRegistry;
            _eventAggregator = eventAggregator;
            _userSession     = userSession;

            Items = new MenuItemsCollection();

            WireUpEvents();
            ApplicationCommands.LoginSucceeded.RegisterCommand(new DelegateCommand <object>(LoginSucceeded));
            LogOutCommand = new DelegateCommand <object>(LogoutUser);
        }
Ejemplo n.º 8
0
        private MenuItemsCollection GetMenuFromRegistry()
        {
            var menuItems = new MenuItemsCollection();

            foreach (var menuInfo in _menuRegistry)
            {
                if (!UserContext.Instance.User.HasPermission(menuInfo.RequiredPermission))
                {
                    continue;
                }
                menuItems.Add(new MenuItem(menuInfo));
            }
            return(menuItems);
        }
Ejemplo n.º 9
0
        private void BtnAddNewMenuItemClicked(object sender, MouseButtonEventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog
                {
                    Multiselect      = false,
                    InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
                };
                if (openFileDialog.ShowDialog() == true)
                {
                    var icon = ToImageSource(System.Drawing.Icon.ExtractAssociatedIcon(openFileDialog.FileName));

                    ReadOnlySpan <char> fileName = openFileDialog.SafeFileName;
                    int lastPeriod = fileName.LastIndexOf('.');
                    if (lastPeriod != -1)
                    {
                        fileName = fileName.Slice(0, lastPeriod).ToString();
                    }

                    MenuItem item = new MenuItem
                    {
                        Icon = icon,
                        Name = fileName.ToString(),
                        NameWithExtension = openFileDialog.SafeFileName,
                        Path        = openFileDialog.FileName,
                        Type        = "Manual",
                        UpdatedDate = DateTime.Now
                    };

                    if (sender.ToString() == "BtnFav")
                    {
                        item.IsFav = true;
                        FavItemsCollection.Add(item);
                    }

                    MenuItemsCollection.Add(item);
                    SaveToJsonDatabase();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
Ejemplo n.º 10
0
 private async void SaveToJsonDatabase()
 {
     try
     {
         JsonSerializerOptions options = new JsonSerializerOptions
         {
             MaxDepth                 = 0,
             IgnoreNullValues         = true,
             IgnoreReadOnlyProperties = true
         };
         await using FileStream createStream = File.Create("Data.Json");
         await JsonSerializer.SerializeAsync(createStream,
                                             MenuItemsCollection.Where(x => x.Type == "Manual" || x.Type == "AutoFav"),
                                             options);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 11
0
        //===============================================================================

        private void LoadAllInstalledPrograms()
        {
            try
            {
                string   s     = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
                string[] files = Directory.GetFiles(s, "*.LNK", SearchOption.AllDirectories);

                foreach (var item in files)
                {
                    try
                    {
                        var lnk      = GetLnkTarget(item);
                        var path     = lnk.TargetPath.Replace('\\', '-').Replace('-', '/');
                        var fullname = lnk.FullName.Split('\\').Last().Split('.')[0];
                        var icon     = System.Drawing.Icon.ExtractAssociatedIcon(path);

                        var program = new MenuItem
                        {
                            Name        = fullname,
                            Path        = lnk.TargetPath,
                            UpdatedDate = DateTime.Now,
                            Type        = "Auto",
                            Icon        = ToImageSource(icon)
                        };

                        if (MenuItemsCollection.FirstOrDefault(x => x.Name == program.Name) == null)
                        {
                            MenuItemsCollection.Add(program);
                        }
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        public void MenuItemsCollection()
        {
            var collection = new MenuItemsCollection();
            var s = MenuItem.GroupNameSeparator;
            var items = new[]
            {
                new MenuItem {GroupName = $"Group1{s}Subgroup1", Text = "Item1"},
                new MenuItem {GroupName = $"Group2{s}Subgroup1{s}Subgroup1", Text = "Item2"},
                new MenuItem {GroupName = $"Group1{s}Subgroup1", Text = "Item3"},
                new MenuItem {GroupName = $"Group2", Text = "Item4"},
                new MenuItem {GroupName = $"Group2{s}Subgroup1{s}Subgroup2", Text = "Item5"},
                new MenuItem {GroupName = $"Group1", Text = "Item6"},
                new MenuItem {GroupName = $"Group1{s}Subgroup1", Text = "Item7"},
            };

            collection.AddToHierarchy(items);
            collection.Count.ShouldBe(2);
            collection[0].Text.ShouldBe("Group1");
            collection[0].Items[1].Text.ShouldBe("Item6");
            collection[0].Items[0].Items[2].Text.ShouldBe("Item7");
            collection[1].Items[0].Items[1].Items[0].Text.ShouldBe("Item5");
        }
Ejemplo n.º 13
0
        private void FavItemsContextMenu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (sender is System.Windows.Controls.MenuItem menu)
                {
                    var item = menu.DataContext as MenuItem;
                    FavItemsCollection.Remove(item);

                    if (item.Type == "AutoFav")
                    {
                        MenuItemsCollection.Remove(item);
                    }

                    item.IsFav = false;
                    SaveToJsonDatabase();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
Ejemplo n.º 14
0
 public MenuItem()
 {
     _items = new MenuItemsCollection(this);
 }
		private void CreateMenuItems()
		{
			/* Instead of loading a XML document, you could query a web service to get the menu items */
			if (this.Source == null) return;

			using (StreamReader reader = new StreamReader(
				Application.GetResourceStream(this.Source).Stream))
			{
				string xaml = reader.ReadToEnd();

				this._items = ParseXaml(xaml);
			}
		}