Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Baimp.AlgorithmTreeView"/> class.
        /// </summary>
        public AlgorithmTreeView(ScanCollection scanCollection)
        {
            nameCol = new DataField<object>();
            store = new TreeStore(nameCol);

            Type baseType = typeof(BaseAlgorithm);
            IEnumerable<Type> algorithms = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(s => s.GetTypes())
                .Where(t => t.BaseType == baseType);

            algorithmCollection = new Dictionary<string, List<BaseAlgorithm>>();
            foreach (Type algorithm in algorithms) {

                BaseAlgorithm instance =
                    Activator.CreateInstance(algorithm, (PipelineNode) null, scanCollection) as BaseAlgorithm;
                string algorithmType = instance.AlgorithmType.ToString();

                if (!algorithmCollection.ContainsKey(algorithmType)) {
                    algorithmCollection[algorithmType] = new List<BaseAlgorithm>();
                }

                algorithmCollection[algorithmType].Add(instance);
            }

            InitializeUI();
        }
Exemplo n.º 2
0
        public ListView2()
        {
            ListView list = new ListView ();
            var editableActiveField = new DataField<bool> ();
            var nonEditableActiveField = new DataField<bool> ();
            var textField = new DataField<string> ();
            var textField2 = new DataField<string> ();
            var editableField = new DataField<bool> ();
            var somewhatEditableData = new DataField<bool>();

            ListStore store = new ListStore(editableActiveField, nonEditableActiveField, textField, textField2, editableField, somewhatEditableData);
            list.DataSource = store;

            list.Columns.Add (new ListViewColumn("Editable", new CheckBoxCellView { Editable = true, ActiveField = editableActiveField }));
            list.Columns.Add (new ListViewColumn("Not Editable", new CheckBoxCellView { Editable = false, ActiveField = nonEditableActiveField }));
            list.Columns.Add (new ListViewColumn("Editable", new TextCellView { Editable = true, TextField = textField }));
            list.Columns.Add(new ListViewColumn("Somewhat Editable", new CheckBoxCellView { EditableField = editableField, ActiveField = somewhatEditableData }));
            list.Columns.Add (new ListViewColumn("Somewhat Editable", new TextCellView { EditableField = editableField, TextField = textField2 }));

            Random rand = new Random ();

            for (int n=0; n<100; n++) {
                var r = store.AddRow ();
                store.SetValue (r, editableActiveField, rand.Next(0, 2) == 0);
                store.SetValue (r, nonEditableActiveField, rand.Next(0, 2) == 0);
                store.SetValue(r, somewhatEditableData, rand.Next(0, 2) == 0);
                store.SetValue (r, textField, n.ToString ());
                var edit = (n % 2) == 0;
                store.SetValue (r, editableField, edit);
                store.SetValue (r, textField2, edit ? "editable" : "not editable");
            }
            PackStart (list, true);
        }
Exemplo n.º 3
0
        public ListViewEntries()
        {
            ListView list = new ListView ();
            var editableTextField = new DataField<string> ();
            var nonEditableTextField = new DataField<string> ();

            ListStore store = new ListStore (editableTextField, nonEditableTextField);
            list.DataSource = store;
            list.GridLinesVisible = GridLines.Horizontal;

            var textCellView = new TextCellView { Editable = true, TextField = editableTextField };
            list.Columns.Add (new ListViewColumn ("Editable", textCellView));
            list.Columns.Add (new ListViewColumn ("Not Editable", new TextCellView { Editable = false, TextField = nonEditableTextField }));

            Random rand = new Random ();

            for (int n = 0; n < 10; n++) {
                var r = store.AddRow ();
                store.SetValue (r, editableTextField, "Editable value " + n);
                store.SetValue (r, nonEditableTextField, "Non-editable value " + n);
            }
            PackStart (list, true);
            var btn = new Button ("Add Row");
            btn.Clicked += delegate {
                var row = store.AddRow ();
                store.SetValues (row, editableTextField, "New editable text", nonEditableTextField, "New non-editable text");
                list.StartEditingCell (row, textCellView);
            };
            PackStart (btn, false, hpos: WidgetPlacement.Start);
        }
Exemplo n.º 4
0
        public ListViewCombos()
        {
            ListView list = new ListView ();
            var indexField = new DataField<int> ();

            var indexField2 = new DataField<int> ();
            var itemsField = new DataField<ItemCollection> ();

            ListStore store = new ListStore (indexField, indexField2, itemsField);
            list.DataSource = store;
            list.GridLinesVisible = GridLines.Horizontal;

            var comboCellView = new ComboBoxCellView { Editable = true, SelectedIndexField = indexField };
            comboCellView.Items.Add (1, "one");
            comboCellView.Items.Add (2, "two");
            comboCellView.Items.Add (3, "three");

            list.Columns.Add (new ListViewColumn ("List 1", comboCellView));

            var comboCellView2 = new ComboBoxCellView { Editable = true, SelectedIndexField = indexField2, ItemsField = itemsField };
            list.Columns.Add (new ListViewColumn ("List 2", comboCellView2));

            int p = 0;
            for (int n = 0; n < 10; n++) {
                var r = store.AddRow ();
                store.SetValue (r, indexField, n % 3);
                var col = new ItemCollection ();
                for (int i = 0; i < 3; i++) {
                    col.Add (p, "p" + p);
                    p++;
                }
                store.SetValues (r, indexField2, n % 3, itemsField, col);
            }
            PackStart (list, true);
        }
Exemplo n.º 5
0
 public static CellView GetDefaultCellView(DataField field)
 {
     if (field.FieldType == typeof(bool))
         return new CheckBoxCellView (field);
     else if (field.FieldType == typeof(Image))
         return new ImageCellView (field);
     return new TextCellView (field);
 }
Exemplo n.º 6
0
 public static CellView GetDefaultCellView(DataField field)
 {
     if (field.Index == -1)
         throw new InvalidOperationException ("Field must be bound to a data source");
     if (field.FieldType == typeof(bool))
         return new CheckBoxCellView (field);
     else if (field.FieldType == typeof(Image))
         return new ImageCellView (field);
     return new TextCellView (field);
 }
Exemplo n.º 7
0
		public override IScrollableWidget CreateScrollableWidget ()
		{
			DataField<string> text = new DataField<string> ();
			TreeStore s = new TreeStore (text);
			var list = new TreeView (s);
			list.Columns.Add ("Hi", text);

			for (int n = 0; n < 100; n++) {
				var r = s.AddNode ();
				r.SetValue (text, n + new string ('.',100));
			}
			return list;
		}
Exemplo n.º 8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public TextEntryHelper()
        {
            // Create text entry
            InnerTextEntry = new TextEntry();

            // Default bind
            InnerTextEntry.Changed += InnerTextEntry_Changed;

            // Self changed - show menu
            Changed += TextEntryHelper_Changed;

            // Key binding events
            InnerTextEntry.KeyReleased += InnerTextEntry_KeyPressed;

            // Helper
            VBox EntryHelper = new VBox();
            EntryHelper.PackStart(InnerTextEntry, true, true);

            // Create list store
            Values = new DataField<string>();
            HelperStore = new ListStore(Values);

            // Create helper list view
            HelperListView = new ListView()
            {
                MinHeight = 75,
                HeightRequest = 75,
                Visible = false,
                HeadersVisible = false,
                DataSource = HelperStore,
                SelectionMode = SelectionMode.Single
            };
            HelperListView.Columns.Add("Name", Values);

            // Click selection
            HelperListView.ButtonReleased += HelperListView_ButtonPressed;

            // Scroll view to
            EntryHelper.PackStart(HelperListView, true, true);

            // Margins
            MarginTop = 4;
            MarginBottom = 5;

            // Set as content
            Content = EntryHelper;

            // Show tree items
            InnerTextEntry.GotFocus += GotFocusHandler;
        }
Exemplo n.º 9
0
        public ListView2()
        {
            ListView list = new ListView();
            var editableActiveField = new DataField<bool>();
            var nonEditableActiveField = new DataField<bool>();
            var textField = new DataField<string>();
            var textField2 = new DataField<string>();
            var editableField = new DataField<bool>();
            var somewhatEditableData = new DataField<bool>();

            ListStore store = new ListStore(editableActiveField, nonEditableActiveField, textField, textField2, editableField, somewhatEditableData);
            list.DataSource = store;
            list.GridLinesVisible = GridLines.Horizontal;

            var checkCellView = new CheckBoxCellView { Editable = true, ActiveField = editableActiveField };
            checkCellView.Toggled += (sender, e) =>
            {

                if (list.CurrentEventRow == 0)
                {
                    MessageDialog.ShowError("CurrentEventRow is null. This is not supposed to happen");
                }
                else
                {
                    store.SetValue(list.CurrentEventRow, textField, "Toggled");
                }
            };

            list.Columns.Add(new ListViewColumn("Editable", checkCellView));
            list.Columns.Add(new ListViewColumn("Not Editable", new CheckBoxCellView { Editable = false, ActiveField = nonEditableActiveField }));
            list.Columns.Add(new ListViewColumn("Editable", new TextCellView { Editable = true, TextField = textField }));
            list.Columns.Add(new ListViewColumn("Somewhat Editable", new CheckBoxCellView { EditableField = editableField, ActiveField = somewhatEditableData }));
            list.Columns.Add(new ListViewColumn("Somewhat Editable", new TextCellView { EditableField = editableField, TextField = textField2 }));

            Random rand = new Random();

            for (int n = 0; n < 100; n++)
            {
                var r = store.AddRow();
                store.SetValue(r, editableActiveField, rand.Next(0, 2) == 0);
                store.SetValue(r, nonEditableActiveField, rand.Next(0, 2) == 0);
                store.SetValue(r, somewhatEditableData, rand.Next(0, 2) == 0);
                store.SetValue(r, textField, n.ToString());
                var edit = (n % 2) == 0;
                store.SetValue(r, editableField, edit);
                store.SetValue(r, textField2, edit ? "editable" : "not editable");
            }
            PackStart(list, true);
        }
Exemplo n.º 10
0
        public ListViewLog(bool squeezeEntries)
        {
            SqueezeEntries = squeezeEntries;

            infoIcon = StockIcons.Information.WithSize(IconSize.Small);
            warningIcon = StockIcons.Warning.WithSize(IconSize.Small);
            errorIcon = StockIcons.Error.WithSize(IconSize.Small);

            imgField = new DataField<Image>();
            typeField = new DataField<string>();
            timestampField = new DataField<string>();
            textField = new DataField<string>();
            objectField = new DataField<string>();
            machineField = new DataField<string>();
            idField = new DataField<ulong>();

            listStore = new ListStore(imgField, objectField, timestampField, typeField, textField, machineField, idField);

            DataSource = listStore;
            Columns.Add("Id", idField);
            Columns.Add("Type", imgField, typeField);
            Columns.Add("Timestamp", timestampField);
            Columns.Add("Source", objectField);
            Columns.Add("Machine", machineField);
            Columns.Add("Text", textField);

            var gtkScrolledWindow = (Gtk.ScrolledWindow)Toolkit.CurrentEngine.GetNativeWidget(this);
            gtkScrolledWindow.Child.CanFocus = false; //can only set this inside GTK since there is a ScrolledWindow wrapper... - should be fixed in XWT
            BorderVisible = false;

            gtkScrolledWindow.Vadjustment.ValueChanged += (sender, e) => 
            {
                var s = Scrolled;
                if (s == null)
                {
                    return;
                }

                if(gtkScrolledWindow.Vadjustment.Value < Epsilon)
                {
                    s(ScrolledState.ScrolledUp);
                }
                else if ((gtkScrolledWindow.Vadjustment.Upper - gtkScrolledWindow.Vadjustment.PageSize) - gtkScrolledWindow.Vadjustment.Value < Epsilon)
                {
                    s(ScrolledState.ScrolledDown);
                }
            };
        }
Exemplo n.º 11
0
        public CoursesController(TreeView treeView, Button btnAddSubject,
            Button btnAddLesson)
        {
            this.treeView = treeView;
            imageCol   = new DataField<Xwt.Drawing.Image>();
            nameCol    = new DataField<string>();
            subjectCol = new DataField<Subject>();
            lessonCol  = new DataField<Lesson>();
            store = new TreeStore(imageCol, nameCol, subjectCol, lessonCol);
            treeView.DataSource = store;
            treeView.Columns.Add("", imageCol, nameCol);

            UpdateView();
            treeView.SelectionChanged += OnTreeSelectionChanged;

            this.btnAddLesson = btnAddLesson;
            btnAddSubject.Clicked += CreateSubject;
            btnAddLesson.Clicked += CreateLesson;
        }
Exemplo n.º 12
0
		public void HiddenTree ()
		{
			var f = new DataField<string> ();
			TreeStore ts = new TreeStore (f);
			var node = ts.AddNode ().SetValue (f, "1").AddChild ().SetValue (f, "2").AddChild ().SetValue (f, "3");
			var tree = new TreeView (ts);

			Window w = new Window ();
			Notebook nb = new Notebook ();
			nb.Add (new Label ("Hi"), "One");
			nb.Add (tree, "Two");
			w.Content = nb;
			ShowWindow (w);

			tree.ScrollToRow (node.CurrentPosition);

			tree.Columns.Add ("Hi", f);

			tree.ScrollToRow (node.CurrentPosition);
		}
Exemplo n.º 13
0
        public ListView2()
        {
            ListView list = new ListView ();
            editable = new DataField<bool> ();
            nonEditable = new DataField<bool> ();
            var textField = new DataField<string> ();
            ListStore store = new ListStore (editable, nonEditable, textField);
            list.DataSource = store;

            list.Columns.Add (new ListViewColumn("Editable", new CheckBoxCellView { Editable = true, ActiveField = editable }));
            list.Columns.Add (new ListViewColumn("Not Editable", new CheckBoxCellView { Editable = false, ActiveField = nonEditable }));
            list.Columns.Add (new ListViewColumn("Editable", new TextCellView { Editable = true, TextField = textField }));

            Random rand = new Random ();

            for (int n=0; n<100; n++) {
                var r = store.AddRow ();
                store.SetValue (r, editable, rand.Next(0, 2) == 0);
                store.SetValue (r, nonEditable, rand.Next(0, 2) == 0);
                store.SetValue (r, textField, n.ToString ());
            }
            PackStart (list, true);
        }
Exemplo n.º 14
0
 public ImageCellView(DataField imageField)
 {
     ImageField = imageField;
 }
Exemplo n.º 15
0
        public OptionView(LauncherWindow window)
        {
            _texturePacks = new List<TexturePack>();
            _lastTexturePack = null;

            Window = window;
            this.MinWidth = 250;

            OptionLabel = new Label("Options")
            {
                Font = Font.WithSize(16),
                TextAlignment = Alignment.Center
            };

            ResolutionLabel = new Label("Select a resolution...");
            ResolutionComboBox = new ComboBox();

            int resolutionIndex = -1;
            for (int i = 0; i < WindowResolution.Defaults.Length; i++)
            {
                ResolutionComboBox.Items.Add(WindowResolution.Defaults[i].ToString());

                if (resolutionIndex == -1)
                {
                    resolutionIndex =
                        ((WindowResolution.Defaults[i].Width == UserSettings.Local.WindowResolution.Width) &&
                        (WindowResolution.Defaults[i].Height == UserSettings.Local.WindowResolution.Height)) ? i : -1;
                }
            }

            if (resolutionIndex == -1)
            {
                ResolutionComboBox.Items.Add(UserSettings.Local.WindowResolution.ToString());
                resolutionIndex = ResolutionComboBox.Items.Count - 1;
            }

            ResolutionComboBox.SelectedIndex = resolutionIndex;
            FullscreenCheckBox = new CheckBox()
            {
                Label = "Fullscreen mode",
                State = (UserSettings.Local.IsFullscreen) ? CheckBoxState.On : CheckBoxState.Off
            };

            TexturePackLabel = new Label("Select a texture pack...");
            TexturePackImageField = new DataField<Image>();
            TexturePackTextField = new DataField<string>();
            TexturePackStore = new ListStore(TexturePackImageField, TexturePackTextField);
            TexturePackListView = new ListView
            {
                MinHeight = 200,
                SelectionMode = SelectionMode.Single,
                DataSource = TexturePackStore,
                HeadersVisible = false
            };
            OpenFolderButton = new Button("Open texture pack folder");
            BackButton = new Button("Back");

            TexturePackListView.Columns.Add("Image", TexturePackImageField);
            TexturePackListView.Columns.Add("Text", TexturePackTextField);

            ResolutionComboBox.SelectionChanged += (sender, e) =>
            {
                UserSettings.Local.WindowResolution =
                    WindowResolution.FromString(ResolutionComboBox.SelectedText);
                UserSettings.Local.Save();
            };

            FullscreenCheckBox.Clicked += (sender, e) =>
            {
                UserSettings.Local.IsFullscreen = !UserSettings.Local.IsFullscreen;
                UserSettings.Local.Save();
            };

            TexturePackListView.SelectionChanged += (sender, e) =>
            {
                var texturePack = _texturePacks[TexturePackListView.SelectedRow];
                if (_lastTexturePack != texturePack)
                {
                    UserSettings.Local.SelectedTexturePack = texturePack.Name;
                    UserSettings.Local.Save();
                }
            };

            OpenFolderButton.Clicked += (sender, e) =>
            {
                var dir = new DirectoryInfo(TexturePack.TexturePackPath);
                Process.Start(dir.FullName);
            };

            BackButton.Clicked += (sender, e) =>
            {
                Window.MainContainer.Remove(this);
                Window.MainContainer.PackEnd(Window.MainMenuView);
            };

            OfficialAssetsButton = new Button("Download Minecraft assets") { Visible = false };
            OfficialAssetsButton.Clicked += OfficialAssetsButton_Clicked;
            OfficialAssetsProgress = new ProgressBar() { Visible = false, Indeterminate = true };

            LoadTexturePacks();

            this.PackStart(OptionLabel);
            this.PackStart(ResolutionLabel);
            this.PackStart(ResolutionComboBox);
            this.PackStart(FullscreenCheckBox);
            this.PackStart(TexturePackLabel);
            this.PackStart(TexturePackListView);
            this.PackStart(OfficialAssetsProgress);
            this.PackStart(OfficialAssetsButton);
            this.PackStart(OpenFolderButton);
            this.PackEnd(BackButton);
        }
Exemplo n.º 16
0
 public T GetValue <T> (int row, DataField <T> column)
 {
     return((T)Backend.GetValue(row, column.Index));
 }
Exemplo n.º 17
0
 public void SetValue <T> (int row, DataField <T> column, T value)
 {
     Backend.SetValue(row, column.Index, value);
 }
Exemplo n.º 18
0
        public SingleplayerView(LauncherWindow window)
        {
            Worlds.Local = new Worlds();
            Worlds.Local.Load();

            Window = window;
            this.MinWidth = 250;

            SingleplayerLabel = new Label("Singleplayer")
            {
                Font = Font.WithSize(16),
                TextAlignment = Alignment.Center
            };
            WorldListView = new ListView
            {
                MinHeight = 200,
                SelectionMode = SelectionMode.Single
            };
            CreateWorldButton = new Button("New world");
            DeleteWorldButton = new Button("Delete") { Sensitive = false };
            PlayButton = new Button("Play") { Sensitive = false };
            BackButton = new Button("Back");
            CreateWorldBox = new VBox() { Visible = false };
            NewWorldName = new TextEntry() { PlaceholderText = "Name" };
            NewWorldSeed = new TextEntry() { PlaceholderText = "Seed (optional)" };
            NewWorldCommit = new Button("Create") { Sensitive = false };
            NewWorldCancel = new Button("Cancel");
            NameField = new DataField<string>();
            WorldListStore = new ListStore(NameField);
            WorldListView.DataSource = WorldListStore;
            WorldListView.HeadersVisible = false;
            WorldListView.Columns.Add(new ListViewColumn("Name", new TextCellView { TextField = NameField, Editable = false }));
            ProgressLabel = new Label("Loading world...") { Visible = false };
            ProgressBar = new ProgressBar() { Visible = false, Indeterminate = true, Fraction = 0 };

            BackButton.Clicked += (sender, e) =>
            {
                Window.MainContainer.Remove(this);
                Window.MainContainer.PackEnd(Window.MainMenuView);
            };
            CreateWorldButton.Clicked += (sender, e) =>
            {
                CreateWorldBox.Visible = true;
            };
            NewWorldCancel.Clicked += (sender, e) =>
            {
                CreateWorldBox.Visible = false;
            };
            NewWorldName.Changed += (sender, e) =>
            {
                NewWorldCommit.Sensitive = !string.IsNullOrEmpty(NewWorldName.Text);
            };
            NewWorldCommit.Clicked += NewWorldCommit_Clicked;
            WorldListView.SelectionChanged += (sender, e) =>
            {
                PlayButton.Sensitive = DeleteWorldButton.Sensitive = WorldListView.SelectedRow != -1;
            };
            PlayButton.Clicked += PlayButton_Clicked;
            DeleteWorldButton.Clicked += (sender, e) =>
            {
                var world = Worlds.Local.Saves[WorldListView.SelectedRow];
                WorldListStore.RemoveRow(WorldListView.SelectedRow);
                Worlds.Local.Saves = Worlds.Local.Saves.Where(s => s != world).ToArray();
                Directory.Delete(world.BaseDirectory, true);
            };

            foreach (var world in Worlds.Local.Saves)
            {
                var row = WorldListStore.AddRow();
                WorldListStore.SetValue(row, NameField, world.Name);
            }

            var createDeleteHbox = new HBox();
            CreateWorldButton.WidthRequest = DeleteWorldButton.WidthRequest = 0.5;
            createDeleteHbox.PackStart(CreateWorldButton, true);
            createDeleteHbox.PackStart(DeleteWorldButton, true);

            CreateWorldBox.PackStart(NewWorldName);
            CreateWorldBox.PackStart(NewWorldSeed);
            var newWorldHbox = new HBox();
            NewWorldCommit.WidthRequest = NewWorldCancel.WidthRequest = 0.5;
            newWorldHbox.PackStart(NewWorldCommit, true);
            newWorldHbox.PackStart(NewWorldCancel, true);
            CreateWorldBox.PackStart(newWorldHbox);

            this.PackStart(SingleplayerLabel);
            this.PackStart(WorldListView);
            this.PackStart(createDeleteHbox);
            this.PackStart(PlayButton);
            this.PackStart(CreateWorldBox);
            this.PackStart(ProgressLabel);
            this.PackStart(ProgressBar);
            this.PackEnd(BackButton);
        }
Exemplo n.º 19
0
        public ComboBoxes()
        {
            HBox box = new HBox ();
            ComboBox c = new ComboBox ();
            c.Items.Add ("One");
            c.Items.Add ("Two");
            c.Items.Add ("Three");
            c.SelectedIndex = 1;
            box.PackStart (c);
            Label la = new Label ();
            box.PackStart (la);
            c.SelectionChanged += delegate {
                la.Text = "Selected: " + (string)c.SelectedItem;
            };
            PackStart (box);

            box = new HBox ();
            ComboBox c2 = new ComboBox ();
            box.PackStart (c2);
            Button b = new Button ("Fill combo (should grow)");
            box.PackStart (b);
            b.Clicked += delegate {
                for (int n=0; n<10; n++) {
                    c2.Items.Add ("Item " + new string ('#', n));
                }
            };
            PackStart (box);

            // Combo with custom labels

            box = new HBox ();
            ComboBox c3 = new ComboBox ();
            c3.Items.Add (0, "Combo with custom labels");
            c3.Items.Add (1, "One");
            c3.Items.Add (2, "Two");
            c3.Items.Add (3, "Three");
            c3.Items.Add (ItemSeparator.Instance);
            c3.Items.Add (4, "Maybe more");
            var la3 = new Label ();
            box.PackStart (c3);
            box.PackStart (la3);
            c3.SelectionChanged += delegate {
                la3.Text = string.Format ("Selected item: {0} with label {1}",
                                          c3.SelectedItem,
                                          c3.SelectedText);
            };
            PackStart (box);

            box = new HBox ();
            var c4 = new ComboBoxEntry ();
            var la4 = new Label ();
            box.PackStart (c4);
            box.PackStart (la4);

            c4.Items.Add (1, "One");
            c4.Items.Add (2, "Two");
            c4.Items.Add (3, "Three");
            c4.TextEntry.PlaceholderText = "This is an entry";
            c4.TextEntry.Changed += delegate {
                la4.Text = "Selected text: " + c4.TextEntry.Text;
            };
            PackStart (box);

            // A complex combobox

            // Three data fields
            var imgField = new DataField<Image> ();
            var textField = new DataField<string> ();
            var descField = new DataField<string> ();

            ComboBox cbox = new ComboBox ();
            ListStore store = new ListStore (textField, imgField, descField);

            cbox.ItemsSource = store;
            var r = store.AddRow ();
            store.SetValue (r, textField, "Information");
            store.SetValue (r, descField, "Icons are duplicated on purpose");
            store.SetValue (r, imgField, Image.FromIcon (StockIcons.Information, IconSize.Small));
            r = store.AddRow ();
            store.SetValue (r, textField, "Error");
            store.SetValue (r, descField, "Another item");
            store.SetValue (r, imgField, Image.FromIcon (StockIcons.Error, IconSize.Small));
            r = store.AddRow ();
            store.SetValue (r, textField, "Warning");
            store.SetValue (r, descField, "A third item");
            store.SetValue (r, imgField, Image.FromIcon (StockIcons.Warning, IconSize.Small));

            // Four views to show three data fields
            cbox.Views.Add (new ImageCellView (imgField));
            cbox.Views.Add (new TextCellView (textField));
            cbox.Views.Add (new ImageCellView (imgField));
            cbox.Views.Add (new TextCellView (descField));

            cbox.SelectedIndex = 0;

            PackStart (cbox);
        }
Exemplo n.º 20
0
        public MultiplayerView(LauncherWindow window)
        {
            Window = window;
            this.MinWidth = 250;

            MultiplayerLabel = new Label("Multiplayer")
            {
                Font = Font.WithSize(16),
                TextAlignment = Alignment.Center
            };
            ServerIPEntry = new TextEntry()
            {
                PlaceholderText = "Server IP",
                Text = UserSettings.Local.LastIP
            };
            ConnectButton = new Button("Connect");
            BackButton = new Button("Back");
            ServerListView = new ListView() { MinHeight = 200, SelectionMode = SelectionMode.Single };
            AddServerButton = new Button("Add server");
            RemoveServerButton = new Button("Remove") { Sensitive = false };
            ServerCreationBox = new VBox() { Visible = false };
            NewServerLabel = new Label("Add new server:") { TextAlignment = Alignment.Center };
            NewServerName = new TextEntry() { PlaceholderText = "Name" };
            NewServerAddress = new TextEntry() { PlaceholderText = "Address" };
            CommitAddNewServer = new Button("Add server");
            CancelAddNewServer = new Button("Cancel");

            var iconField = new DataField<Image>();
            var nameField = new DataField<string>();
            var playersField = new DataField<string>();
            ServerListStore = new ListStore(iconField, nameField, playersField);
            ServerListView.DataSource = ServerListStore;
            ServerListView.HeadersVisible = false;
            ServerListView.Columns.Add(new ListViewColumn("Icon", new ImageCellView { ImageField = iconField }));
            ServerListView.Columns.Add(new ListViewColumn("Name", new TextCellView { TextField = nameField }));
            ServerListView.Columns.Add(new ListViewColumn("Players", new TextCellView { TextField = playersField }));

            ServerIPEntry.KeyReleased += (sender, e) => 
            {
                if (e.Key == Key.Return || e.Key == Key.NumPadEnter)
                    ConnectButton_Clicked(sender, e);
            };
            BackButton.Clicked += (sender, e) =>
            {
                Window.InteractionBox.Remove(this);
                Window.InteractionBox.PackEnd(Window.MainMenuView);
            };
            ConnectButton.Clicked += ConnectButton_Clicked;
            ServerListView.SelectionChanged += (sender, e) => 
            {
                RemoveServerButton.Sensitive = ServerListView.SelectedRow != -1;
                ServerIPEntry.Sensitive = ServerListView.SelectedRow == -1;
            };
            AddServerButton.Clicked += (sender, e) => 
            {
                AddServerButton.Sensitive = false;
                RemoveServerButton.Sensitive = false;
                ConnectButton.Sensitive = false;
                ServerListView.Sensitive = false;
                ServerIPEntry.Sensitive = false;
                ServerCreationBox.Visible = true;
            };
            CancelAddNewServer.Clicked += (sender, e) => 
            {
                AddServerButton.Sensitive = true;
                RemoveServerButton.Sensitive = true;
                ConnectButton.Sensitive = true;
                ServerListView.Sensitive = true;
                ServerIPEntry.Sensitive = true;
                ServerCreationBox.Visible = false;
            };
            RemoveServerButton.Clicked += (sender, e) => 
            {
                var server = UserSettings.Local.FavoriteServers[ServerListView.SelectedRow];
                ServerListStore.RemoveRow(ServerListView.SelectedRow);
                UserSettings.Local.FavoriteServers = UserSettings.Local.FavoriteServers.Where(
                    s => s.Name != server.Name && s.Address != server.Address).ToArray();
                UserSettings.Local.Save();
            };
            CommitAddNewServer.Clicked += (sender, e) => 
            {
                var server = new FavoriteServer
                {
                    Name = NewServerName.Text,
                    Address = NewServerAddress.Text
                };
                var row = ServerListStore.AddRow();
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TrueCraft.Launcher.Content.default-server-icon.png"))
                    ServerListStore.SetValue(row, iconField, Image.FromStream(stream));
                ServerListStore.SetValue(row, nameField, server.Name);
                ServerListStore.SetValue(row, playersField, "TODO/50");
                UserSettings.Local.FavoriteServers = UserSettings.Local.FavoriteServers.Concat(new[] { server }).ToArray();
                UserSettings.Local.Save();
                AddServerButton.Sensitive = true;
                RemoveServerButton.Sensitive = true;
                ConnectButton.Sensitive = true;
                ServerListView.Sensitive = true;
                ServerIPEntry.Sensitive = true;
                ServerCreationBox.Visible = false;
            };

            foreach (var server in UserSettings.Local.FavoriteServers)
            {
                var row = ServerListStore.AddRow();
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TrueCraft.Launcher.Content.default-server-icon.png"))
                    ServerListStore.SetValue(row, iconField, Image.FromStream(stream));
                ServerListStore.SetValue(row, nameField, server.Name);
                ServerListStore.SetValue(row, playersField, "TODO/50");
            }

            var addServerHBox = new HBox();
            AddServerButton.WidthRequest = RemoveServerButton.WidthRequest = 0.5;
            addServerHBox.PackStart(AddServerButton, true);
            addServerHBox.PackStart(RemoveServerButton, true);

            var commitHBox = new HBox();
            CancelAddNewServer.WidthRequest = CommitAddNewServer.WidthRequest = 0.5;
            commitHBox.PackStart(CommitAddNewServer, true);
            commitHBox.PackStart(CancelAddNewServer, true);

            ServerCreationBox.PackStart(NewServerLabel);
            ServerCreationBox.PackStart(NewServerName);
            ServerCreationBox.PackStart(NewServerAddress);
            ServerCreationBox.PackStart(commitHBox);

            this.PackEnd(BackButton);
            this.PackEnd(ConnectButton);
            this.PackStart(MultiplayerLabel);
            this.PackStart(ServerIPEntry);
            this.PackStart(ServerListView);
            this.PackStart(addServerHBox);
            this.PackStart(ServerCreationBox);
        }
        public void LoadQuery(StoredQuery query)
        {
            listView.Columns.Clear();
            using (var progress = new MonoDevelop.Ide.ProgressMonitoring.MessageDialogProgressMonitor(true, false, false))
            {
                var fields = CachedMetaData.Instance.Fields;
                WorkItemStore store = new WorkItemStore(query);
                var data = store.LoadByPage(progress);
                if (data.Count > 0)
                {
                    var firstItem = data[0];
                    List<IDataField> dataFields = new List<IDataField>();
                    var mapping = new Dictionary<Field, IDataField<object>>();
                    foreach (var item in firstItem.WorkItemInfo.Keys)
                    {
                        var field = fields[item];
                        var dataField = new DataField<object>();
                        dataFields.Add(dataField);
                        mapping.Add(field, dataField);
                    }

                    if (dataFields.Any())
                    {
                        if (ShowCheckboxes)
                        {
                            isCheckedField = new DataField<bool>();
                            dataFields.Insert(0, isCheckedField);
                            var checkColumn = new CheckBoxCellView(isCheckedField) { Editable = true };
                            checkColumn.Toggled += (sender, e) => 
                            {
                                var astore = (TreeStore)listView.DataSource;
                                var node = astore.GetNavigatorAt(listView.CurrentEventRow);
                                var workItem = node.GetValue(workItemField);
                                if (!node.GetValue(isCheckedField))
                                {
                                    if (OnSelectWorkItem != null)
                                        OnSelectWorkItem(workItem);
                                }
                                else
                                {
                                    if (OnRemoveWorkItem != null)
                                        OnRemoveWorkItem(workItem);
                                }
                            };
                            listView.Columns.Add("", checkColumn);
                        }
                        workItemField = new DataField<WorkItem>();
                        dataFields.Insert(0, workItemField);
                        var listStore = new TreeStore(dataFields.ToArray());
                        foreach (var map in mapping)
                        {
                            listView.Columns.Add(map.Key.Name, map.Value);
                        }
                        listView.DataSource = listStore;
                        foreach (var workItem in data)
                        {
                            var row = listStore.AddNode();
                            row.SetValue(workItemField, workItem);
                            foreach (var map in mapping)
                            {
                                object value;
                                if (workItem.WorkItemInfo.TryGetValue(map.Key.ReferenceName, out value))
                                {
                                    row.SetValue(map.Value, value);
                                }
                                else
                                {
                                    row.SetValue(map.Value, null);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
		public ComboBoxes ()
		{
			HBox box = new HBox ();
			ComboBox c = new ComboBox ();
			c.Items.Add ("One");
			c.Items.Add ("Two");
			c.Items.Add ("Three");
			c.SelectedIndex = 1;
			box.PackStart (c);
			Label la = new Label ();
			box.PackStart (la);
			c.SelectionChanged += delegate {
				la.Text = "Selected: " + (string)c.SelectedItem;
			};
			PackStart (box);
			
			box = new HBox ();
			ComboBox c2 = new ComboBox ();
			box.PackStart (c2);
			Button b = new Button ("Fill combo (should grow)");
			box.PackStart (b);
			b.Clicked += delegate {
				for (int n=0; n<10; n++) {
					c2.Items.Add ("Item " + new string ('#', n));
				}
			};
			PackStart (box);
			
			// Combo with custom labels
			
			box = new HBox ();
			ComboBox c3 = new ComboBox ();
			c3.Items.Add (0, "Combo with custom labels");
			c3.Items.Add (1, "One");
			c3.Items.Add (2, "Two");
			c3.Items.Add (3, "Three");
			c3.Items.Add (ItemSeparator.Instance);
			c3.Items.Add (4, "Maybe more");
			var la3 = new Label ();
			box.PackStart (c3);
			box.PackStart (la3);
			c3.SelectionChanged += delegate {
				la3.Text = string.Format ("Selected item: {0} with label {1}",
				                          c3.SelectedItem,
				                          c3.SelectedText);
			};
			PackStart (box);
			
			box = new HBox ();
			var c4 = new ComboBoxEntry ();
			var la4 = new Label ();
			box.PackStart (c4);
			box.PackStart (la4);
			
			c4.Items.Add (1, "One");
			c4.Items.Add (2, "Two");
			c4.Items.Add (3, "Three");
			c4.TextEntry.PlaceholderText = "This is an entry";
			c4.TextEntry.Changed += delegate {
				la4.Text = "Selected text: " + c4.TextEntry.Text;
			};
			PackStart (box);

			HBox selBox = new HBox ();
			Label las = new Label ("Selection:");
			selBox.PackStart (las);
			Button selReplace = new Button ("Replace");
			selReplace.Clicked += delegate {
				c4.TextEntry.SelectedText = "[TEST]";
			};
			selBox.PackEnd (selReplace);
			Button selAll = new Button ("Select all");
			selAll.Clicked += delegate {
				c4.TextEntry.SelectionStart = 0;
				c4.TextEntry.SelectionLength = c4.TextEntry.Text.Length;
			};
			selBox.PackEnd (selAll);
			Button selPlus = new Button ("+");
			selPlus.Clicked += delegate {
				c4.TextEntry.SelectionLength++;
			};
			selBox.PackEnd (selPlus);
			Button selRight = new Button (">");
			selRight.Clicked += delegate {
				c4.TextEntry.SelectionStart++;
			};
			selBox.PackEnd (selRight);
			PackStart (selBox);

			c4.TextEntry.SelectionChanged += delegate {
				las.Text = "Selection: (" + c4.TextEntry.CursorPosition + " <-> " + c4.TextEntry.SelectionStart + " + " + c4.TextEntry.SelectionLength + ") " + c4.TextEntry.SelectedText;
			};


			var c5 = new ComboBoxEntry ();
			c5.TextEntry.TextAlignment = Alignment.Center;
			c5.TextEntry.Text = "centered text with red background";
			c5.BackgroundColor = Colors.Red;
			c5.Items.Add (1, "One");
			c5.Items.Add (2, "Two");
			c5.Items.Add (3, "Three");
			PackStart (c5);

			// A complex combobox
			
			// Three data fields
			var imgField = new DataField<Image> ();
			var textField = new DataField<string> ();
			var descField = new DataField<string> ();
			
			ComboBox cbox = new ComboBox ();
			ListStore store = new ListStore (textField, imgField, descField);
			
			cbox.ItemsSource = store;
			var r = store.AddRow ();
			store.SetValue (r, textField, "Information");
			store.SetValue (r, descField, "Icons are duplicated on purpose");
			store.SetValue (r, imgField, StockIcons.Information);
			r = store.AddRow ();
			store.SetValue (r, textField, "Error");
			store.SetValue (r, descField, "Another item");
			store.SetValue (r, imgField, StockIcons.Error);
			r = store.AddRow ();
			store.SetValue (r, textField, "Warning");
			store.SetValue (r, descField, "A third item");
			store.SetValue (r, imgField, StockIcons.Warning);
			
			// Four views to show three data fields
			cbox.Views.Add (new ImageCellView (imgField));
			cbox.Views.Add (new TextCellView (textField));
			cbox.Views.Add (new ImageCellView (imgField));
			cbox.Views.Add (new TextCellView (descField));
			
			cbox.SelectedIndex = 0;
			
			PackStart (cbox);
		}
Exemplo n.º 23
0
 public TextCellView(DataField textField)
 {
     TextField = textField;
 }
        public void LoadQuery(StoredQuery query)
        {
            listView.Columns.Clear();
            using (var progress = new MonoDevelop.Ide.ProgressMonitoring.MessageDialogProgressMonitor(true, false, false))
            {
                var fields = CachedMetaData.Instance.Fields;
                WorkItemStore store = new WorkItemStore(query);
                var data = store.LoadByPage(progress);
                if (data.Count > 0)
                {
                    var firstItem = data[0];
                    List<IDataField> dataFields = new List<IDataField>();
                    var mapping = new Dictionary<Field, IDataField<object>>();
                    foreach (var item in firstItem.WorkItemInfo.Keys)
                    {
                        var field = fields[item];
                        var dataField = new DataField<object>();
                        dataFields.Add(dataField);
                        mapping.Add(field, dataField);
                    }

                    if (dataFields.Any())
                    {
                        workItemField = new DataField<WorkItem>();
                        dataFields.Insert(0, workItemField);
                        var listStore = new ListStore(dataFields.ToArray());
                        foreach (var map in mapping)
                        {
                            listView.Columns.Add(map.Key.Name, map.Value);
                        }
                        listView.DataSource = listStore;
                        foreach (var workItem in data)
                        {
                            var row = listStore.AddRow();
                            listStore.SetValue(row, workItemField, workItem);
                            foreach (var map in mapping)
                            {
                                object value;
                                if (workItem.WorkItemInfo.TryGetValue(map.Key.ReferenceName, out value))
                                {
                                    listStore.SetValue(row, map.Value, value);
                                }
                                else
                                {
                                    listStore.SetValue(row, map.Value, null);
                                }
                            }
                        }
                    }
                }
            }
        }