private async void AppBar_NewPartButton_Click(object sender, RoutedEventArgs e)
        {
            if (_editor.Part == null)
            {
                NewFile();
                return;
            }

            var partType = await ChoosePartType(true);

            if (!string.IsNullOrEmpty(partType))
            {
                // Reset viewing parameters
                UcEditor.ResetView(false);

                // Create package and part
                var package = _editor.Part.Package;

                _lastSelectedBlock?.Dispose();
                _lastSelectedBlock = null;

                _editor.Part.Dispose();
                _editor.Part = null;

                var part = package.CreatePart(partType);
                _editor.Part = part;
                Title.Text   = _packageName + " - " + part.Type;
            }
        }
        public void Closing()
        {
            _previousBlock?.Dispose();
            _previousBlock = null;

            _currentBlock?.Dispose();
            _currentBlock = null;

            _activeBlock?.Dispose();
            _activeBlock = null;

            _selectedBlock?.Dispose();
            _selectedBlock = null;
        }
        private void UcEditor_RightDown(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            // Only for Pen to avoid issue with LongPress becoming RightTap with Pen/Touch
            var uiElement = sender as UIElement;
            var p         = e.GetCurrentPoint(uiElement);

            if (e.Pointer.PointerDeviceType != Windows.Devices.Input.PointerDeviceType.Pen)
            {
                return;
            }

            if (!p.Properties.IsRightButtonPressed)
            {
                return;
            }

            _lastPointerPosition = new Graphics.Point((float)p.Position.X, (float)p.Position.Y);
            _lastSelectedBlock?.Dispose();
            _lastSelectedBlock = _editor.HitBlock(_lastPointerPosition.X, _lastPointerPosition.Y);

            if ((_lastSelectedBlock == null) || (_lastSelectedBlock.Type == "Container"))
            {
                _lastSelectedBlock?.Dispose();
                _lastSelectedBlock = _editor.GetRootBlock();
            }

            if (_lastSelectedBlock != null)
            {
                var globalPos = e.GetCurrentPoint(null).Position;
                DisplayContextualMenu(globalPos);
            }

            e.Handled = true;
        }
        private void UcEditor_RightTapped(object sender, Windows.UI.Xaml.Input.RightTappedRoutedEventArgs e)
        {
            // Only for Mouse to avoid issue with LongPress becoming RightTap with Pen/Touch
            if (e.PointerDeviceType != Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                return;
            }

            var uiElement = sender as UIElement;
            var pos       = e.GetPosition(uiElement);

            _lastPointerPosition = new Graphics.Point((float)pos.X, (float)pos.Y);
            _lastSelectedBlock?.Dispose();
            _lastSelectedBlock = _editor.HitBlock(_lastPointerPosition.X, _lastPointerPosition.Y);

            if ((_lastSelectedBlock == null) || (_lastSelectedBlock.Type == "Container"))
            {
                _lastSelectedBlock?.Dispose();
                _lastSelectedBlock = _editor.GetRootBlock();
            }

            if (_lastSelectedBlock != null)
            {
                var globalPos = e.GetPosition(null);
                DisplayContextualMenu(globalPos);
            }

            e.Handled = true;
        }
        public void OnPartChanged()
        {
            _previousBlock?.Dispose();
            _previousBlock = null;

            _currentBlock?.Dispose();
            _currentBlock = null;

            _activeBlock?.Dispose();
            _activeBlock = null;

            _selectedBlock?.Dispose();
            _selectedBlock = null;

            UpdateData();
            ResetWidgets();
        }
        private void Previous_Click(object sender, RoutedEventArgs e)
        {
            var part = _editor.Part;

            if (part != null)
            {
                var index = part.Package.IndexOfPart(part);

                if (index > 0)
                {
                    // Reset viewing parameters
                    UcEditor.ResetView(false);

                    // Select new part
                    _lastSelectedBlock?.Dispose();
                    _lastSelectedBlock = null;

                    _editor.Part = null;

                    var newPart = part.Package.GetPart(index - 1);
                    _editor.Part = newPart;
                    Type.Text    = _packageName + " - " + newPart.Type;

                    part.Dispose();
                }
            }
        }
예제 #7
0
        private async void AppBar_NewPartButton_Click(object sender, RoutedEventArgs e)
        {
            if (_editor.Part == null)
            {
                NewFile();
                return;
            }

            var partType = await ChoosePartType(true);

            if (!string.IsNullOrEmpty(partType))
            {
                // Reset viewing parameters
                UcEditor.ResetView(false);

                _lastSelectedBlock?.Dispose();
                _lastSelectedBlock = null;

                var previousPart = _editor.Part;
                var package      = previousPart.Package;

                try
                {
                    _editor.Part = null;

                    var part = package.CreatePart(partType);
                    _editor.Part = part;
                    Title.Text   = _packageName + " - " + part.Type;

                    previousPart.Dispose();
                }
                catch (Exception ex)
                {
                    _editor.Part = previousPart;
                    Title.Text   = _packageName + " - " + _editor.Part.Type;

                    var msgDialog = new MessageDialog(ex.ToString());
                    await msgDialog.ShowAsync();
                }
            }
        }
 private void Remove(object sender, RoutedEventArgs e)
 {
     try
     {
         if (_lastSelectedBlock != null)
         {
             _editor.RemoveBlock(_lastSelectedBlock);
             _lastSelectedBlock.Dispose();
             _lastSelectedBlock = null;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
 private async void Popup_CommandHandler_Remove(FlyoutCommand command)
 {
     try
     {
         if (_lastSelectedBlock != null && _lastSelectedBlock.Type != "Container")
         {
             _editor.RemoveBlock(_lastSelectedBlock);
             _lastSelectedBlock.Dispose();
             _lastSelectedBlock = null;
         }
     }
     catch (Exception ex)
     {
         var msgDialog = new MessageDialog(ex.ToString());
         await msgDialog.ShowAsync();
     }
 }
        private void UcEditor_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            var pos = e.GetPosition(UcEditor);

            _lastPointerPosition = new Graphics.Point((float)pos.X, (float)pos.Y);
            _lastSelectedBlock?.Dispose();
            _lastSelectedBlock = _editor.HitBlock(_lastPointerPosition.X, _lastPointerPosition.Y);

            if ((_lastSelectedBlock == null) || (_lastSelectedBlock.Type == "Container"))
            {
                _lastSelectedBlock?.Dispose();
                _lastSelectedBlock = _editor.GetRootBlock();
            }

            if (_lastSelectedBlock != null)
            {
                ShowContextMenu();
                e.Handled = true;
            }
        }
        private void Previous_Click(object sender, RoutedEventArgs e)
        {
            var part = _editor.Part;

            if (part != null)
            {
                var package = part.Package;
                var index   = package.IndexOfPart(part);

                if (index > 0)
                {
                    // Reset viewing parameters
                    UcEditor.ResetView(false);

                    _lastSelectedBlock?.Dispose();
                    _lastSelectedBlock = null;
                    _editor.Part       = null;

                    while (--index >= 0)
                    {
                        ContentPart newPart = null;

                        try
                        {
                            // Select new part
                            newPart      = part.Package.GetPart(index);
                            _editor.Part = newPart;
                            Type.Text    = _packageName + " - " + newPart.Type;
                            part.Dispose();
                            break;
                        }
                        catch
                        {
                            // Can't set this part, try the previous one
                            _editor.Part = null;
                            Type.Text    = "";
                            newPart?.Dispose();
                        }
                    }

                    if (index < 0)
                    {
                        // Restore current part if none can be set
                        _editor.Part = part;
                        Type.Text    = _packageName + " - " + part.Type;
                    }
                }
            }
        }
        private void UcEditor_Holding(object sender, Windows.UI.Xaml.Input.HoldingRoutedEventArgs e)
        {
            // Only for Pen and Touch (but it should not been fired for a Mouse)
            // Do not wait for the Release event, open the menu immediately

            if (e.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                return;
            }

            if (e.HoldingState != Windows.UI.Input.HoldingState.Started)
            {
                return;
            }

            var uiElement = sender as UIElement;
            var pos       = e.GetPosition(uiElement);

            _lastPointerPosition = new Graphics.Point((float)pos.X, (float)pos.Y);
            _lastSelectedBlock?.Dispose();
            _lastSelectedBlock = _editor.HitBlock(_lastPointerPosition.X, _lastPointerPosition.Y);

            if ((_lastSelectedBlock == null) || (_lastSelectedBlock.Type == "Container"))
            {
                _lastSelectedBlock?.Dispose();
                _lastSelectedBlock = _editor.GetRootBlock();
            }

            // Discard current stroke
            UcEditor.CancelSampling(UcEditor.GetPointerId(e));

            if (_lastSelectedBlock != null)
            {
                var globalPos = e.GetPosition(null);
                DisplayContextualMenu(globalPos);
            }

            e.Handled = true;
        }
 private void BackupData()
 {
     _previousBlock?.Dispose();
     _previousBlock = _currentBlock?.ShallowCopy();
     _previousWords = CloneWords(_currentWords);
 }