<commit_before>﻿using motoi.platform.ui;
using motoi.platform.ui.actions;
using motoi.platform.ui.data;
using motoi.platform.ui.factories;
using motoi.platform.ui.images;
using motoi.platform.ui.shells;
using motoi.platform.ui.widgets;
using motoi.workbench.model;
using motoi.workbench.registries;
using Xcite.Collections;

namespace motoi.workbench.menu {
    /// <summary>
    /// Implements an action that displays all available views in a dialog window and provides 
    /// the option to open a selected one.
    /// </summary>
    public class ShowViewsMenuHandler : AbstractActionHandler {
        /// <inheritdoc />
        public override void Run() {
            ITitledAreaDialog dialogWindow = UIFactory.NewShell<ITitledAreaDialog>();
            dialogWindow.Title = "Registered Views";
            dialogWindow.Description = "Select a view to open";
            dialogWindow.WindowWidth = 440;
            
            IGridComposite gridComposite = UIFactory.NewWidget<IGridComposite>(dialogWindow);

            gridComposite.GridColumns = 1;
            gridComposite.GridRows = 1;
            IListViewer listViewer = UIFactory.NewWidget<IListViewer>(gridComposite);
            gridComposite.AddWidget(listViewer);

            IViewReference selectedViewReference = null;
            bool closedOk = false;
            listViewer.ContentProvider = new ListViewerContentProviderImpl();
            listViewer.LabelProvider = new ListViewerLabelProviderImpl();
            listViewer.Input = DataViewRegistry.Instance.GetViewReferences().ToArray();
            listViewer.Update();
            listViewer.SelectionChanged += (sender, args) => selectedViewReference = (IViewReference) args.Selection;
            dialogWindow.AddButton("OK", () => {
                closedOk = true;
                dialogWindow.Close();
            });
            dialogWindow.AddButton("Cancel", () => dialogWindow.Close());

            dialogWindow.SetContent(gridComposite);
            dialogWindow.Show(true);

            if (closedOk && selectedViewReference != null) {
                string viewId = selectedViewReference.Id;
                PlatformUI.Instance.Workbench.ActivePerspective.OpenView(viewId, EViewPosition.Bottom);
            }
        }

        /// <summary>
        /// Implements <see cref="IListLabelProvider"/> for a set of <see cref="IViewReference"/>.
        /// </summary>
        class ListViewerLabelProviderImpl : IListLabelProvider {
            /// <inheritdoc />
            public string GetText(object item) {
                return ((IViewReference) item).Title;
            }

            /// <inheritdoc />
            public ImageDescriptor GetImage(object item) {
                return null;
            }

            /// <inheritdoc />
            public string GetToolTipText(object item) {
                return null;
            }<commit_msg>Switched button order<commit_after>﻿using motoi.platform.ui;
using motoi.platform.ui.actions;
using motoi.platform.ui.data;
using motoi.platform.ui.factories;
using motoi.platform.ui.images;
using motoi.platform.ui.shells;
using motoi.platform.ui.widgets;
using motoi.workbench.model;
using motoi.workbench.registries;
using Xcite.Collections;

namespace motoi.workbench.menu {
    /// <summary>
    /// Implements an action that displays all available views in a dialog window and provides 
    /// the option to open a selected one.
    /// </summary>
    public class ShowViewsMenuHandler : AbstractActionHandler {
        /// <inheritdoc />
        public override void Run() {
            ITitledAreaDialog dialogWindow = UIFactory.NewShell<ITitledAreaDialog>();
            dialogWindow.Title = "Registered Views";
            dialogWindow.Description = "Select a view to open";
            dialogWindow.WindowWidth = 440;
            
            IGridComposite gridComposite = UIFactory.NewWidget<IGridComposite>(dialogWindow);

            gridComposite.GridColumns = 1;
            gridComposite.GridRows = 1;
            IListViewer listViewer = UIFactory.NewWidget<IListViewer>(gridComposite);
            gridComposite.AddWidget(listViewer);

            IViewReference selectedViewReference = null;
            bool closedOk = false;
            listViewer.ContentProvider = new ListViewerContentProviderImpl();
            listViewer.LabelProvider = new ListViewerLabelProviderImpl();
            listViewer.Input = DataViewRegistry.Instance.GetViewReferences().ToArray();
            listViewer.Update();
            listViewer.SelectionChanged += (sender, args) => selectedViewReference = (IViewReference) args.Selection;
            dialogWindow.AddButton("Cancel", () => dialogWindow.Close());
            dialogWindow.AddButton("OK", () => {
                closedOk = true;
                dialogWindow.Close();
            });

            dialogWindow.SetContent(gridComposite);
            dialogWindow.Show(true);

            if (closedOk && selectedViewReference != null) {
                string viewId = selectedViewReference.Id;
                PlatformUI.Instance.Workbench.ActivePerspective.OpenView(viewId, EViewPosition.Bottom);
            }
        }

        /// <summary>
        /// Implements <see cref="IListLabelProvider"/> for a set of <see cref="IViewReference"/>.
        /// </summary>
        class ListViewerLabelProviderImpl : IListLabelProvider {
            /// <inheritdoc />
            public string GetText(object item) {
                return ((IViewReference) item).Title;
            }

            /// <inheritdoc />
            public ImageDescriptor GetImage(object item) {
                return null;
            }

            /// <inheritdoc />
            public string GetToolTipText(object item) {
                return null;
            }
{'fraction_non_alphanumeric': 0.0981067125645439, 'fraction_numerical': 0.0017211703958691911, 'mean_word_length': 2.2122719734660032, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3105932', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1432, 'n_words': 308}