Esempio n. 1
0
        public override void Execute(object parameter)
        {
            Window window = parameter as Window;

            ElementDialog dialog = new ElementDialog();

            dialog.Owner = window;
            dialog.ShowDialog();
        }
        /// <summary>
        /// <c>EA_MenuClick</c> events are received by an Add-In in response to user selection of a menu option.
        /// The event is raised when the user clicks on a particular menu option. When a user clicks on one of your non-parent menu options, your Add-In receives a <c>MenuClick</c> event.
        /// Notice that your code can directly access Enterprise Architect data and UI elements using Repository methods.
        /// </summary>
        /// <param name="repository"><c>An EA.Repository</c> object representing the currently open Enterprise Architect model. Poll its members to retrieve model data and user interface status information.</param>
        /// <param name="location">Not used</param>
        /// <param name="menuName">The name of the parent menu for which sub-items are to be defined.
        /// In the case of the top-level menu this is an empty string.</param>
        /// <param name="itemName">The name of the option actually clicked.</param>
        public void EA_MenuClick(Repository repository, string location, string menuName, string itemName)
        {
            var itemType = repository.GetContextItemType();

            switch (itemType)
            {
            case ObjectType.otElement:
                _window    = new ElementDialog();
                _viewModel = new ElementDialogViewModel
                {
                    Repository = repository
                };
                break;

            case ObjectType.otPackage:
                _window    = new PackageDialog();
                _viewModel = new PackageDialogViewModel
                {
                    Repository = repository
                };
                break;

            case ObjectType.otAttribute:
                _window    = new AttributeDialog();
                _viewModel = new AttributeDialogViewModel
                {
                    Repository = repository
                };
                break;

            case ObjectType.otConnector:
                _window    = new ConnectorDialog();
                _viewModel = new ConnectorDialogViewModel
                {
                    Repository = repository
                };
                break;
            }

            //Create new ResourceDictionary and set source for language matching the selected menu option
            var dict = new ResourceDictionary();

            switch (itemName)
            {
            case DanishMenuOption:
                dict.Source = new Uri("pack://application:,,,/PlusprofilAddin;component/Resources/StringResources.da-DK.xaml",
                                      UriKind.Absolute);
                break;

            case EnglishMenuOption:
                dict.Source = new Uri("pack://application:,,,/PlusprofilAddin;component/Resources/StringResources.en-US.xaml",
                                      UriKind.Absolute);
                break;

            default:
                throw new ArgumentException("Invalid Menu Option selected");
            }
            _window.Resources.MergedDictionaries.Add(dict);
            _viewModel.ResourceDictionary = dict;
            _viewModel.Initialize();
            _window.DataContext = _viewModel;

            // Set window size
            _window.MinHeight = _window.Height = 512;
            _window.MinWidth  = _window.Width = 576;

            // Increase size for Connector dialogs
            if (_window is ConnectorDialog)
            {
                _window.MinHeight = _window.Height = 512;
                _window.MinWidth  = _window.Width = 768;
            }

            _window.Closing += _viewModel.OnWindowClosing;

            _window.ShowDialog();
        }