Beispiel #1
0
 /// <summary>
 /// Method to invoke when the Rename command is executed.
 /// </summary>
 private void Rename()
 {
     if (SelectedItems.Count == 1)
     {
         MessageBoxService mbs = new MessageBoxService();
         var result            = mbs.GetUserInput("Please enter the new name.", "Rename", SelectedItem.Name);
         if (result.Result == MessageResult.OK)
         {
             SelectedItems.First().Name = PropModelServices.Instance().Uniquify(result.Response);
         }
     }
     else
     {
         PatternRenameSelectedItems();
     }
 }
Beispiel #2
0
 /// <summary>
 /// Method to invoke when the TemplateRename command is executed.
 /// </summary>
 private void TemplateRename()
 {
     if (SelectedItems.Count == 1)
     {
         var dependencyResolver = this.GetDependencyResolver();
         var mbs    = dependencyResolver.Resolve <IMessageBoxService>();
         var result = mbs.GetUserInput("Please enter the new name.", "Rename", SelectedItems[0].ElementModel.Name);
         if (result.Result == MessageResult.OK)
         {
             SelectedItems.First().Name = PropModelServices.Instance().Uniquify(result.Response);
         }
     }
     else
     {
         PatternRenameSelectedItems();
     }
 }
Beispiel #3
0
        List <MemberDescriptor> GetDescriptors()
        {
            List <MemberDescriptor> list = new List <MemberDescriptor>();
            var service = (SingleItem ?? SelectedItems.First()).Services.GetService <IComponentPropertyService>();

            if (SelectedItems.Count() == 1)
            {
                list.AddRange(service.GetAvailableProperties(SingleItem));
                list.AddRange(service.GetAvailableEvents(SingleItem));
            }
            else
            {
                list.AddRange(service.GetCommonAvailableProperties(SelectedItems));
            }

            return(list);
        }
        //private async void FileExplorerItemSelect(object sender, GestureEventArgs e)
        //{
        //    var item = ((FrameworkElement) sender).Tag as FileExplorerItem;

        //    if (item == null)
        //    {
        //        return;
        //    }

        //    if (item.IsFolder)
        //    {
        //        GetTreeForFolder(await FolderTree.First()
        //            .GetFolderAsync(item.Name));
        //    }
        //    else
        //    {
        //        if (SelectionMode == SelectionMode.FileWithOpen)
        //        {

        //            SelectedSingleItem(item);
        //        }
        //    }
        //}

        private async void btnOpen_Click(object sender, RoutedEventArgs e)
        {
            var check = sender as CheckBox;

            if (check != null)
            {
                check.IsChecked = false;
            }

            ProcessSelectedItems();

            if (SelectionMode == SelectionMode.FileWithOpen)
            {
                try
                {
                    IStorageFolderEx folder = FolderTree.Pop();

                    if (SelectedItems == null || !SelectedItems.Any())
                    {
                        Dismiss(folder);
                        return;
                    }

                    IStorageFileEx file = await folder.GetFileAsync(SelectedItems.First().Name);

                    if (file != null)
                    {
                        Dismiss(file);
                        return;
                    }

                    Dismiss(folder);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Can't Dismiss", ex.Message);
                }

                Dismiss(null);
            }
            else
            {
                Dismiss(SelectedItems);
            }
        }
        /// <summary>
        /// Method to invoke when the MatchLightSize command is executed.
        /// </summary>
        private void MatchLightSize()
        {
            if (SelectedItems.Count < 2)
            {
                return;
            }
            var lvmReference = SelectedItems.First();
            var emReference  = PropModelServices.Instance().GetElementModel(lvmReference.Light.ParentModelId);

            foreach (var lightViewModel in SelectedItems.Skip(1))
            {
                var em = PropModelServices.Instance().GetElementModel(lightViewModel.Light.ParentModelId);
                if (em != null)
                {
                    em.LightSize = emReference.LightSize;
                }
            }
        }
Beispiel #6
0
        private async Task ExportFileAsync()
        {
            PakFileBrowserFileItem file = SelectedItems.First();

            var picker = new FileSavePicker {
                SuggestedFileName = file.DisplayName
            };

            picker.FileTypeChoices.Add($"{file.Extension} files", new List <string> {
                file.Extension
            });

            var saveFile = await picker.PickSaveFileAsync();

            if (saveFile != null)
            {
                Stream input;
                if (EncryptionKey == null)
                {
                    input = await CurrentPak.GetEntryStreamAsync(file.Metadata);
                }
                else
                {
                    input = await CurrentPak.GetEntryStreamAsync(file.Metadata, EncryptionKey);
                }

                using (input)
                    using (var output = await saveFile.OpenStreamForWriteAsync())
                    {
                        await input.CopyToAsync(output);
                    }

                var flyout = new Flyout()
                {
                    Content = new TextBlock {
                        Text = $"File saved!"
                    },
                    Placement = FlyoutPlacementMode.Bottom
                };
                flyout.ShowAt((FrameworkElement)Window.Current.Content);
            }
        }
Beispiel #7
0
        public NowPlayingViewModel()
        {
            _playbackController = IoC.Get <PlaybackController>();

            SelectionChangedCommand = new ReactiveCommand();
            SelectionChangedCommand.Where(x => x != null)
            .Select(x => ((IEnumerable)x).Cast <TrackStateViewModel>())
            .Subscribe(x => SelectedItems = x);

            RemoveSelectedCommand = new ReactiveCommand();
            RemoveSelectedCommand.Subscribe(param =>
                                            new List <TrackStateViewModel>(SelectedItems)
                                            .ForEach(x => Playlist.Remove(x)));

            RemoveAllCommand = new ReactiveCommand();
            RemoveAllCommand.Subscribe(param => Playlist.Clear());

            PlaySelectedCommand = new ReactiveCommand();
            PlaySelectedCommand.Subscribe(param => _playbackController.Play(SelectedItems.First()));
        }
 public void SelectionChanged(IList items)
 {
     SelectedItems.Clear();
     foreach(MusicFileTag item in items)
     {
         SelectedItems.Add(item);
     }
     // if select only one file we show the details
     if (SelectedItems.Count.Equals(1))
     {
         ItemSelected = SelectedItems.First();
         DetailVM.SetItemToShow(ItemSelected);
         DetColWidth = new GridLength(400, GridUnitType.Pixel);
     }
     else
     {
         DetColWidth = new GridLength(1, GridUnitType.Pixel);
         ItemSelected = null;
     }
 }
Beispiel #9
0
        /// <summary>
        /// Method to invoke when the MoveToGroup command is executed.
        /// </summary>
        private void MoveToGroup()
        {
            var result = RequestNewGroupName(String.Empty);

            if (result.Result == MessageResult.OK)
            {
                var pms = PropModelServices.Instance();

                //See if we are moving all items and can place the new group them under our parent group.
                ElementModel parentForGroup       = null;
                var          firstParentViewModel = SelectedItems.First().ParentViewModel as ElementModelViewModel;
                if (firstParentViewModel != null && !firstParentViewModel.Children.Except(SelectedItems.Select(x => x.ElementModel)).Any())
                {
                    parentForGroup = firstParentViewModel?.ElementModel;
                }

                var parentToJoin = pms.CreateNode(result.Response, parentForGroup);
                foreach (var elementModelViewModel in SelectedItems.ToList())
                {
                    elementModelViewModel.IsSelected = false;
                    ElementModel parentToLeave = (elementModelViewModel.ParentViewModel as ElementModelViewModel)?.ElementModel;
                    if (parentToLeave != null)
                    {
                        pms.AddToParent(elementModelViewModel.ElementModel, parentToJoin);
                        pms.RemoveFromParent(elementModelViewModel.ElementModel, parentToLeave);
                    }
                }
                OnModelsChanged();

                DeselectAll();
                var newModel = ElementModelLookUpService.Instance.GetModels(parentToJoin.Id);
                if (newModel != null && newModel.Any())
                {
                    newModel.First().IsExpanded = true;
                    SelectModels(newModel);
                }
            }
        }
        private async void TokenizingTextBox_CharacterReceived(UIElement sender, CharacterReceivedRoutedEventArgs args)
        {
            var container = ContainerFromItem(_currentTextEdit) as TokenizingTextBoxItem;

            if (container != null && !(GetFocusedElement().Equals(container._autoSuggestTextBox) || char.IsControl(args.Character)))
            {
                if (SelectedItems.Count > 0)
                {
                    var index = _innerItemsSource.IndexOf(SelectedItems.First());

                    await RemoveAllSelectedTokens();

                    // Wait for removal of old items
                    _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        // If we're before the last textbox and it's empty, redirect focus to that one instead
                        if (index == _innerItemsSource.Count - 1 && string.IsNullOrWhiteSpace(_lastTextEdit.Text))
                        {
                            var lastContainer = ContainerFromItem(_lastTextEdit) as TokenizingTextBoxItem;

                            lastContainer.UseCharacterAsUser = true; // Make sure we trigger a refresh of suggested items.

                            _lastTextEdit.Text = string.Empty + args.Character;

                            UpdateCurrentTextEdit(_lastTextEdit);

                            lastContainer._autoSuggestTextBox.SelectionStart = 1; // Set position to after our new character inserted

                            lastContainer._autoSuggestTextBox.Focus(FocusState.Keyboard);
                        }
                        else
                        {
                            //// Otherwise, create a new textbox for this text.

                            UpdateCurrentTextEdit(new PretokenStringContainer((string.Empty + args.Character).Trim())); // Trim so that 'space' isn't inserted and can be used to insert a new box.

                            _innerItemsSource.Insert(index, _currentTextEdit);

                            // Need to wait for containerization
                            _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                var newContainer = ContainerFromIndex(index) as TokenizingTextBoxItem; // Should be our last text box

                                newContainer.UseCharacterAsUser = true;                                // Make sure we trigger a refresh of suggested items.

                                void WaitForLoad(object s, RoutedEventArgs eargs)
                                {
                                    if (newContainer._autoSuggestTextBox != null)
                                    {
                                        newContainer._autoSuggestTextBox.SelectionStart = 1; // Set position to after our new character inserted

                                        newContainer._autoSuggestTextBox.Focus(FocusState.Keyboard);
                                    }

                                    newContainer.Loaded -= WaitForLoad;
                                }

                                newContainer.AutoSuggestTextBoxLoaded += WaitForLoad;
                            });
                        }
                    });
                }
                else
                {
                    // TODO: It looks like we're setting selection and focus together on items? Not sure if that's what we want...
                    // If that's the case, don't think this code will ever be called?

                    //// TODO: Behavior question: if no items selected (just focus) does it just go to our last active textbox?
                    //// Community voted that typing in the end box made sense

                    if (_innerItemsSource[_innerItemsSource.Count - 1] is ITokenStringContainer textToken)
                    {
                        var last     = ContainerFromIndex(Items.Count - 1) as TokenizingTextBoxItem; // Should be our last text box
                        var position = last._autoSuggestTextBox.SelectionStart;
                        textToken.Text = last._autoSuggestTextBox.Text.Substring(0, position) + args.Character +
                                         last._autoSuggestTextBox.Text.Substring(position);

                        last._autoSuggestTextBox.SelectionStart = position + 1; // Set position to after our new character inserted

                        last._autoSuggestTextBox.Focus(FocusState.Keyboard);
                    }
                }
            }
        }
Beispiel #11
0
        private async void TokenizingTextBox_CharacterReceived(UIElement sender, CharacterReceivedRoutedEventArgs args)
        {
            var container = ContainerFromItem(_currentTextEdit) as TokenizingTextBoxItem;

            if (container != null && !(GetFocusedElement().Equals(container._autoSuggestTextBox) || char.IsControl(args.Character)))
            {
                if (SelectedItems.Count > 0)
                {
                    var index = _innerItemsSource.IndexOf(SelectedItems.First());

                    await RemoveAllSelectedTokens();

                    // Wait for removal of old items
                    var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
                    _ = dispatcherQueue.EnqueueAsync(
                        () =>
                    {
                        // If we're before the last textbox and it's empty, redirect focus to that one instead
                        if (index == _innerItemsSource.Count - 1 && string.IsNullOrWhiteSpace(_lastTextEdit.Text))
                        {
                            var lastContainer = ContainerFromItem(_lastTextEdit) as TokenizingTextBoxItem;

                            lastContainer.UseCharacterAsUser = true;     // Make sure we trigger a refresh of suggested items.

                            _lastTextEdit.Text = string.Empty + args.Character;

                            UpdateCurrentTextEdit(_lastTextEdit);

                            lastContainer._autoSuggestTextBox.SelectionStart = 1;     // Set position to after our new character inserted

                            lastContainer._autoSuggestTextBox.Focus(FocusState.Keyboard);
                        }
                        else
                        {
                            //// Otherwise, create a new textbox for this text.

                            UpdateCurrentTextEdit(new PretokenStringContainer((string.Empty + args.Character).Trim()));     // Trim so that 'space' isn't inserted and can be used to insert a new box.

                            _innerItemsSource.Insert(index, _currentTextEdit);

                            // Need to wait for containerization
                            _ = dispatcherQueue.EnqueueAsync(
                                () =>
                            {
                                var newContainer = ContainerFromIndex(index) as TokenizingTextBoxItem; // Should be our last text box

                                newContainer.UseCharacterAsUser = true;                                // Make sure we trigger a refresh of suggested items.

                                void WaitForLoad(object s, RoutedEventArgs eargs)
                                {
                                    if (newContainer._autoSuggestTextBox != null)
                                    {
                                        newContainer._autoSuggestTextBox.SelectionStart = 1;         // Set position to after our new character inserted

                                        newContainer._autoSuggestTextBox.Focus(FocusState.Keyboard);
                                    }

                                    newContainer.Loaded -= WaitForLoad;
                                }

                                newContainer.AutoSuggestTextBoxLoaded += WaitForLoad;
                            }, DispatcherQueuePriority.Normal);
                        }
                    }, DispatcherQueuePriority.Normal);
                }
                else
                {
                    // If no items are selected, send input to the last active string container.
                    // This code is only fires during an edgecase where an item is in the process of being deleted and the user inputs a character before the focus has been redirected to a string container.
                    if (_innerItemsSource[_innerItemsSource.Count - 1] is ITokenStringContainer textToken)
                    {
                        var last           = ContainerFromIndex(Items.Count - 1) as TokenizingTextBoxItem; // Should be our last text box
                        var text           = last._autoSuggestTextBox.Text;
                        var selectionStart = last._autoSuggestTextBox.SelectionStart;
                        var position       = selectionStart > text.Length ? text.Length : selectionStart;
                        textToken.Text = text.Substring(0, position) + args.Character +
                                         text.Substring(position);

                        last._autoSuggestTextBox.SelectionStart = position + 1; // Set position to after our new character inserted

                        last._autoSuggestTextBox.Focus(FocusState.Keyboard);
                    }
                }
            }
        }
Beispiel #12
0
        private async Task SwapFileAsync()
        {
            var metadata = SelectedItems.First().Metadata;

            var picker = new FileOpenPicker();

            picker.FileTypeFilter.Add("*");
            var newFile = await picker.PickSingleFileAsync();

            if (newFile != null)
            {
                using (var stream = await newFile.OpenStreamForReadAsync())
                    using (var bufferStream = new MemoryStream())
                    {
                        await stream.CopyToAsync(bufferStream);

                        if (bufferStream.Length > metadata.Size)
                        {
                            await new MessageDialog($"New file size is bigger than the original file! The new file size must be less than {metadata.Size} bytes.").ShowAsync();
                            return;
                        }

                        if (bufferStream.Length < metadata.Size)
                        {
                            long sizeDifference = metadata.Size - bufferStream.Length;

                            var swapPaddingDialog = new SwapPaddingDialog();
                            if (await swapPaddingDialog.ShowAsync() == ContentDialogResult.Primary)
                            {
                                byte padByte;
                                switch (swapPaddingDialog.FilePadding)
                                {
                                case FilePadding.NullBytes:
                                default:
                                    padByte = 0x00;
                                    break;

                                case FilePadding.Spaces:
                                    padByte = (byte)' ';
                                    break;
                                }

                                byte[] padding = new byte[sizeDifference];
                                Array.Fill(padding, padByte);

                                await bufferStream.WriteAsync(padding, 0, padding.Length);
                            }
                        }

                        await CurrentPak.SwapEntryAsync(metadata, bufferStream);

                        OnPropertyChanged(nameof(CurrentView));

                        var flyout = new Flyout()
                        {
                            Content = new TextBlock {
                                Text = $"File replaced!"
                            },
                            Placement = FlyoutPlacementMode.Bottom
                        };
                        flyout.ShowAt((FrameworkElement)Window.Current.Content);
                    }
            }
        }