コード例 #1
0
ファイル: ListView1.cs プロジェクト: dellis1972/xwt
        public ListView1()
        {
            PackStart (new Label ("The listview should have a red background"));
            ListView list = new ListView () {
                BackgroundColor = Colors.Red
            };
            ListStore store = new ListStore (name, icon, text, icon2);
            list.DataSource = store;
            list.Columns.Add ("Name", icon, name);
            list.Columns.Add ("Text", icon2, text);

            var png = Image.FromResource (typeof(App), "class.png");

            for (int n=0; n<100; n++) {
                var r = store.AddRow ();
                store.SetValue (r, icon, png);
                store.SetValue (r, name, "Value " + n);
                store.SetValue (r, icon2, png);
                store.SetValue (r, text, "Text " + n);
            }
            PackStart (list, BoxMode.FillAndExpand);

            list.RowActivated += delegate(object sender, ListViewRowEventArgs e) {
                MessageDialog.ShowMessage ("Row " + e.RowIndex + " activated");
            };
        }
コード例 #2
0
ファイル: ListBoxSample.cs プロジェクト: shines77/xwt
        public ListBoxSample()
        {
            // Default list box

            ListBox list = new ListBox ();

            for (int n=0; n<100; n++)
                list.Items.Add ("Value " + n);

            PackStart (list, true);

            // Custom list box

            ListBox customList = new ListBox ();
            ListStore store = new ListStore (name, icon);
            customList.DataSource = store;
            customList.Views.Add (new ImageCellView (icon));
            customList.Views.Add (new TextCellView (name));

            var png = Image.FromResource (typeof(App), "class.png");

            for (int n=0; n<100; n++) {
                var r = store.AddRow ();
                store.SetValue (r, icon, png);
                store.SetValue (r, name, "Value " + n);
            }
            PackStart (customList, true);
        }
コード例 #3
0
ファイル: ListViewEntries.cs プロジェクト: akrisiun/xwt
        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);
        }
コード例 #4
0
ファイル: ListView1.cs プロジェクト: StEvUgnIn/xwt
		public ListView1 ()
		{
			PackStart (new Label ("The listview should have a red background"));
			ListView list = new ListView ();
			list.GridLinesVisible = GridLines.Both;
			ListStore store = new ListStore (name, icon, text, icon2, progress);
			list.DataSource = store;
			list.Columns.Add ("Name", icon, name);
			list.Columns.Add ("Text", icon2, text);
			list.Columns.Add ("Progress", new TextCellView () { TextField = text }, new CustomCell () { ValueField = progress });

			var png = Image.FromResource (typeof(App), "class.png");

			Random rand = new Random ();
			
			for (int n=0; n<100; n++) {
				var r = store.AddRow ();
				store.SetValue (r, icon, png);
				store.SetValue (r, name, "Value " + n);
				store.SetValue (r, icon2, png);
				store.SetValue (r, text, "Text " + n);
				store.SetValue (r, progress, new CellData { Value = rand.Next () % 100 });
			}
			PackStart (list, true);

			list.RowActivated += delegate(object sender, ListViewRowEventArgs e) {
				MessageDialog.ShowMessage ("Row " + e.RowIndex + " activated");
			};

			Menu contextMenu = new Menu ();
			contextMenu.Items.Add (new MenuItem ("Test menu"));
			list.ButtonPressed += delegate(object sender, ButtonEventArgs e) {
				int row = list.GetRowAtPosition(new Point(e.X, e.Y));
				if (e.Button == PointerButton.Right && row >= 0) {
					// Set actual row to selected
					list.SelectRow(row);
					contextMenu.Popup(list, e.X, e.Y);
				}
			};

			var but = new Button ("Scroll one line");
			but.Clicked += delegate {
				list.VerticalScrollControl.Value += list.VerticalScrollControl.StepIncrement;
			};
			PackStart (but);

			var spnValue = new SpinButton ();
			spnValue.MinimumValue = 0;
			spnValue.MaximumValue = 99;
			spnValue.IncrementValue = 1;
			spnValue.Digits = 0;
			var btnScroll = new Button ("Go!");
			btnScroll.Clicked += (sender, e) => list.ScrollToRow((int)spnValue.Value);

			HBox scrollActBox = new HBox ();
			scrollActBox.PackStart (new Label("Scroll to Value: "));
			scrollActBox.PackStart (spnValue);
			scrollActBox.PackStart (btnScroll);
			PackStart (scrollActBox);
		}
コード例 #5
0
ファイル: ListView1.cs プロジェクト: nbros/xwt
        public ListView1()
        {
            PackStart (new Label ("The listview should have a red background"));
            ListView list = new ListView ();
            ListStore store = new ListStore (name, icon, text, icon2, progress);
            list.DataSource = store;
            list.Columns.Add ("Name", icon, name);
            list.Columns.Add ("Text", icon2, text);
            list.Columns.Add ("Progress", new CustomCell () { ValueField = progress });

            var png = Image.FromResource (typeof(App), "class.png");

            Random rand = new Random ();

            for (int n=0; n<100; n++) {
                var r = store.AddRow ();
                store.SetValue (r, icon, png);
                store.SetValue (r, name, "Value " + n);
                store.SetValue (r, icon2, png);
                store.SetValue (r, text, "Text " + n);
                store.SetValue (r, progress, rand.Next () % 100);
            }
            PackStart (list, true);

            list.RowActivated += delegate(object sender, ListViewRowEventArgs e) {
                MessageDialog.ShowMessage ("Row " + e.RowIndex + " activated");
            };

            var but = new Button ("Scroll one line");
            but.Clicked += delegate {
                list.VerticalScrollControl.Value += list.VerticalScrollControl.StepIncrement;
            };
            PackStart (but);
        }
コード例 #6
0
ファイル: ListViewCombos.cs プロジェクト: akrisiun/xwt
        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);
        }
コード例 #7
0
ファイル: ListBoxSample.cs プロジェクト: StEvUgnIn/xwt
		public ListBoxSample ()
		{
			// Default list box
			
			ListBox list = new ListBox ();
			
			for (int n=0; n<100; n++)
				list.Items.Add ("Value " + n);
			
			PackStart (list, true);
			
			// Custom list box
			
			ListBox customList = new ListBox ();
			customList.GridLinesVisible = true;
			ListStore store = new ListStore (name, icon);
			customList.DataSource = store;
			customList.Views.Add (new ImageCellView (icon));
			customList.Views.Add (new TextCellView (name));
			
			var png = Image.FromResource (typeof(App), "class.png");
			
			for (int n=0; n<100; n++) {
				var r = store.AddRow ();
				store.SetValue (r, icon, png);
				store.SetValue (r, name, "Value " + n);
			}
			PackStart (customList, true);

			var spnValue = new SpinButton ();
			spnValue.MinimumValue = 0;
			spnValue.MaximumValue = 99;
			spnValue.IncrementValue = 1;
			spnValue.Digits = 0;
			var btnScroll = new Button ("Go!");
			btnScroll.Clicked += (sender, e) => customList.ScrollToRow((int)spnValue.Value);

			HBox scrollActBox = new HBox ();
			scrollActBox.PackStart (new Label("Scroll to Value: "));
			scrollActBox.PackStart (spnValue);
			scrollActBox.PackStart (btnScroll);
			PackStart (scrollActBox);
		}	
コード例 #8
0
ファイル: ListView1.cs プロジェクト: RevolutionSmythe/xwt
        public ListView1()
        {
            ListView list = new ListView ();
            ListStore store = new ListStore (name, icon, text, icon2);
            list.DataSource = store;
            list.Columns.Add ("Name", icon, name);
            list.Columns.Add ("Text", icon2, text);

            var png = Image.FromResource (typeof(App), "class.png");

            for (int n=0; n<100; n++) {
                var r = store.AddRow ();
                store.SetValue (r, icon, png);
                store.SetValue (r, name, "Value " + n);
                store.SetValue (r, icon2, png);
                store.SetValue (r, text, "Text " + n);
            }
            PackStart (list, BoxMode.FillAndExpand);
        }
コード例 #9
0
ファイル: ListView2.cs プロジェクト: nite2006/xwt
        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);
        }
コード例 #10
0
ファイル: ListViewTests.cs プロジェクト: m13253/xwt
		public override IScrollableWidget CreateScrollableWidget ()
		{
			DataField<string> text = new DataField<string> ();
			ListStore s = new ListStore (text);
			var list = new ListView (s);
			list.Columns.Add ("Hi", text);

			for (int n = 0; n < 100; n++) {
				var r = s.AddRow ();
				s.SetValue (r, text, n + new string ('.',100));
			}
			return list;
		}
コード例 #11
0
ファイル: ListView2.cs プロジェクト: neiz/xwt
        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);
        }
コード例 #12
0
ファイル: ListView2.cs プロジェクト: sergueik/xwt_swd
        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);
        }
コード例 #13
0
ファイル: WidgetFocus.cs プロジェクト: m13253/xwt
		public WidgetFocus ()
		{
			var text = new TextEntry ();
			var check = new CheckBox ("CheckBox");
			var slider = new HSlider ();
			ListStore store = new ListStore (value);
			var list = new ListView (store);
			list.Columns.Add ("Value", value);
			list.HeadersVisible = false;
			for (int n=0; n<10; n++) {
				var r = store.AddRow ();
				store.SetValue (r, value, "Value " + n);
			}

			var btn1 = new Button ("TextEnty");
			var btn2 = new Button ("Checkbox");
			var btn3 = new Button ("Slider");
			var btn4 = new Button ("ListBox");
			var btn5 = new Button ("Button");

			btn1.Clicked += (sender, e) => text.SetFocus ();
			btn2.Clicked += (sender, e) => check.SetFocus ();
			btn3.Clicked += (sender, e) => slider.SetFocus ();
			btn4.Clicked += (sender, e) => list.SetFocus ();
			btn5.Clicked += (sender, e) => btn1.SetFocus ();

			var btnBox = new HBox ();
			btnBox.PackStart (btn1);
			btnBox.PackStart (btn2);
			btnBox.PackStart (btn3);
			btnBox.PackStart (btn4);
			btnBox.PackStart (btn5);

			var focusBox = new HBox ();
			var vbox = new VBox ();
			vbox.PackStart (text);
			vbox.PackStart (check);
			vbox.PackStart (slider);
			focusBox.PackStart (vbox);
			focusBox.PackStart (list, true);

			PackStart (btnBox);
			PackStart (focusBox, true);
		}
コード例 #14
0
        void OnEnvironmentClicked(object s, Gtk.ToggledArgs args)
        {
            TreeIter iter;

            storeEnvs.GetIterFromString(out iter, args.Path);

            bool             sel = (bool)storeEnvs.GetValue(iter, 0);
            string           env = (string)storeEnvs.GetValue(iter, 2);
            StringCollection col = radioOnlyShowIn.Active ? entry.OnlyShowIn : entry.NotShowIn;

            if (sel)
            {
                col.Remove(env);
            }
            else
            {
                col.Add(env);
            }

            storeEnvs.SetValue(iter, 0, !sel);
            NotifyChanged();
        }
コード例 #15
0
        void StoreValuesInSelectedTool(object sender, EventArgs e)
        {
            if (lockStoreValues)
            {
                return;
            }
            ExternalTool selectedItem = SelectedTool;

            if (selectedItem == null)
            {
                return;
            }

            toolListBoxStore.SetValue(SelectedIter, 0, titleTextBox.Text);
            selectedItem.MenuCommand        = titleTextBox.Text;
            selectedItem.Command            = browseButton.Path;
            selectedItem.Arguments          = argumentTextBox.Text;
            selectedItem.InitialDirectory   = workingDirTextBox.Text;
            selectedItem.PromptForArguments = promptArgsCheckBox.Active;
            selectedItem.UseOutputPad       = useOutputPadCheckBox.Active;
            selectedItem.SaveCurrentFile    = saveCurrentFileCheckBox.Active;
        }
コード例 #16
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;

            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);
        }
コード例 #17
0
ファイル: UserTasksView.cs プロジェクト: wzq0621/monodevelop
        void OnPropertyUpdated(object sender, EventArgs e)
        {
            highPrioColor   = StringToColor(IdeApp.Preferences.UserTasksHighPrioColor);
            normalPrioColor = StringToColor(IdeApp.Preferences.UserTasksNormalPrioColor);
            lowPrioColor    = StringToColor(IdeApp.Preferences.UserTasksLowPrioColor);

            TreeIter iter;

            if (store.GetIterFirst(out iter))
            {
                do
                {
                    TaskListEntry task = (TaskListEntry)store.GetValue(iter, (int)Columns.UserTask);
                    store.SetValue(iter, (int)Columns.Foreground, GetColorByPriority(task.Priority));
                } while (store.IterNext(ref iter));
            }
        }
コード例 #18
0
        protected override void OnChanged()
        {
            EqualizerSetting eq = ActiveEqualizer;

            if (eq != null)
            {
                active_eq = eq;
            }
            else if (eq == null && active_eq == null)
            {
                base.OnChanged();
                return;
            }
            else if (eq == null)
            {
                eq = active_eq;
            }

            if (Entry == null)
            {
                return;
            }

            eq.Name = Entry.Text;

            TreeIter iter;

            if (GetIterForEqualizerSetting(eq, out iter))
            {
                store.SetValue(iter, 0, eq.Name);
            }

            if (eq != ActiveEqualizer)
            {
                ActiveEqualizer = eq;
                base.OnChanged();
            }
        }
コード例 #19
0
        private void Load()
        {
            ListStore listStore = new ListStore(typeof(bool), typeof(string), typeof(BasePaymentType));

            for (int i = (int)BasePaymentType.Cash; i <= (int)BasePaymentType.Advance; i++)
            {
                BasePaymentType paymentType = (BasePaymentType)i;
                listStore.AppendValues(selected.Contains(paymentType),
                                       PaymentType.GetBasePaymentTypeName(paymentType), paymentType);
            }

            CellRendererToggle cellRendererToggle = new CellRendererToggle {
                Activatable = true
            };

            cellRendererToggle.Toggled += (sender, e) =>
            {
                TreeIter row;
                listStore.GetIter(out row, new TreePath(e.Path));
                bool            value       = !(bool)listStore.GetValue(row, 0);
                BasePaymentType paymentType = (BasePaymentType)listStore.GetValue(row, 2);
                if (value)
                {
                    selected.Add(paymentType);
                }
                else
                {
                    selected.Remove(paymentType);
                }
                listStore.SetValue(row, 0, value);
            };

            treeView.AppendColumn(string.Empty, cellRendererToggle, "active", 0);
            treeView.AppendColumn(string.Empty, new CellRendererText(), "text", 1);
            treeView.AppendColumn(string.Empty, new CellRendererText(), "text", 2).Visible = false;

            treeView.Model = listStore;
        }
コード例 #20
0
        public void Redo()
        {
            if (historyPointer >= history.Count - 1)
            {
                throw new InvalidOperationException("Redo stack is empty");
            }

            historyPointer++;
            BaseHistoryItem item = history[historyPointer];

            item.Redo();
            item.State = HistoryItemState.Undo;
            ListStore.SetValue(item.Id, 0, item);
            history[historyPointer] = item;

            if (historyPointer == history.Count - 1)
            {
                PintaCore.Actions.Edit.Redo.Sensitive = false;
                CanRedo = false;
            }

            if (historyPointer == cleanPointer)
            {
                document.IsDirty = false;
            }
            else if (item.CausesDirty)
            {
                document.IsDirty = true;
            }

            if (history.Count > 1)
            {
                PintaCore.Actions.Edit.Undo.Sensitive = true;
                CanUndo = true;
            }

            PintaCore.History.OnActionRedone();
        }
コード例 #21
0
        public void Redo()
        {
            if (Pointer >= history.Count - 1)
            {
                throw new InvalidOperationException("Redo stack is empty");
            }

            Pointer++;

            var item = history[Pointer];

            item.Redo();
            item.State = HistoryItemState.Undo;
            ListStore.SetValue(item.Id, 0, item);
            history[Pointer] = item;

            if (Pointer == history.Count - 1)
            {
                PintaCore.Actions.Edit.Redo.Sensitive = false;
            }

            if (Pointer == clean_pointer)
            {
                document.IsDirty = false;
            }
            else if (item.CausesDirty)
            {
                document.IsDirty = true;
            }

            if (history.Count > 1)
            {
                PintaCore.Actions.Edit.Undo.Sensitive = true;
            }

            ActionRedone?.Invoke(this, EventArgs.Empty);
        }
コード例 #22
0
        void OnPropertyEdited(object sender, EditedArgs args)
        {
            TreeIter iter;

            if (!store.GetIterFromString(out iter, args.Path))
            {
                return;
            }

            store.SetValue(iter, colPropertyNameIndex, args.NewText);
            if (!CheckAndUpdateConflictMessage(iter, true))
            {
                // unselect this field
                store.SetValue(iter, colCheckedIndex, false);
            }

            UpdateOKButton();
        }
コード例 #23
0
        public void Undo()
        {
            if (Pointer < 0)
            {
                throw new InvalidOperationException("Undo stack is empty");
            }
            else
            {
                var item = history[Pointer];
                item.Undo();
                item.State = HistoryItemState.Redo;

                if (item.CausesDirty)
                {
                    document.IsDirty = true;
                }

                ListStore.SetValue(item.Id, 0, item);
                history[Pointer] = item;
                Pointer--;
            }

            if (Pointer == clean_pointer)
            {
                document.IsDirty = false;
            }

            if (Pointer == 0)
            {
                PintaCore.Actions.Edit.Undo.Sensitive = false;
            }

            PintaCore.Actions.Edit.Redo.Sensitive = true;

            ActionUndone?.Invoke(this, EventArgs.Empty);
        }
コード例 #24
0
ファイル: ProfileDialog.cs プロジェクト: MrJoe/lat
        void OnClassToggled(object o, ToggledArgs args)
        {
            TreeIter iter;

            if (pluginStore.GetIter(out iter, new TreePath(args.Path)))
            {
                bool   old  = (bool)pluginStore.GetValue(iter, 0);
                string name = (string)pluginStore.GetValue(iter, 1);

                ViewPlugin vp = Global.Plugins.GetViewPlugin(name, conn.Settings.Name);

                if (!conn.ServerViews.Contains(vp.GetType().ToString()))
                {
                    conn.ServerViews.Add(vp.GetType().ToString());
                }
                else
                {
                    conn.ServerViews.Remove(vp.GetType().ToString());
                }

                Global.Connections [conn.Settings.Name] = conn;
                pluginStore.SetValue(iter, 0, !old);
            }
        }
コード例 #25
0
        void OnToggled(object s, ToggledArgs args)
        {
            Gtk.TreeIter toggledIter, iter;
            bool         selected;
            bool         value;

            if (!fileStore.GetIterFromString(out toggledIter, args.Path))
            {
                return;
            }

            selected = (bool)fileStore.GetValue(toggledIter, 2);

            baseMap = null;
            if (fileStore.GetIterFirst(out iter))
            {
                do
                {
                    if (toggledIter.Equals(iter))
                    {
                        // this is the node the user toggled, so toggle it
                        value = !selected;
                        if (value)
                        {
                            baseMap = (HeapSnapshot)fileStore.GetValue(iter, 0);
                        }
                    }
                    else
                    {
                        // turn off all other nodes, we can only have one node selected at the same time.
                        value = false;
                    }
                    fileStore.SetValue(iter, 2, value);
                }while (fileStore.IterNext(ref iter));
            }
        }
コード例 #26
0
        private void CreateListOperations()
        {
            ListStore listStore = new ListStore(typeof(bool), typeof(string), typeof(OperationType));

            foreach (OperationType operationType in new [] { OperationType.Purchase, OperationType.Sale, OperationType.Consignment, OperationType.SalesOrder })
            {
                listStore.AppendValues(false, Translator.GetOperationTypeGlobalName(operationType), operationType);
            }

            CellRendererToggle cellRendererToggle = new CellRendererToggle {
                Activatable = true
            };

            cellRendererToggle.Toggled += (sender, e) =>
            {
                TreeIter row;
                listStore.GetIter(out row, new TreePath(e.Path));
                bool          value         = !(bool)listStore.GetValue(row, 0);
                OperationType operationType = (OperationType)listStore.GetValue(row, 2);
                if (value)
                {
                    priceRule.Operations.Add(operationType);
                }
                else
                {
                    priceRule.Operations.Remove(operationType);
                }
                listStore.SetValue(row, 0, value);
                RefreshPreview();
            };

            treeViewOperations.AppendColumn(string.Empty, cellRendererToggle, "active", 0);
            treeViewOperations.AppendColumn(string.Empty, new CellRendererText(), "text", 1);
            treeViewOperations.AppendColumn(string.Empty, new CellRendererText(), "text", 2).Visible = false;
            treeViewOperations.Model = listStore;
        }
コード例 #27
0
        internal void FillData()
        {
            Loading(true);

            _listStore.Clear();

            Task.Run(async() =>
            {
                var apps = new List <Models.Application>();

                try
                {
                    apps = _controller.LoadApplications();
                }
                catch (Exception ex)
                {
                    LoggingService.LogError("Load applications failed.", ex);
                    MessageService.ShowError("An error ocurred loading the applications.", ex);
                }

                await Runtime.RunInMainThread(() =>
                {
                    if (apps.Any())
                    {
                        foreach (var app in apps)
                        {
                            var row = _listStore.AddRow();
                            _listStore.SetValue(row, _nameField, app.Name);
                            _listStore.SetValue(row, _ownerField, app.OwnerName);
                            _listStore.SetValue(row, _appField, app);
                        }

                        if (apps.Any())
                        {
                            _listView.SelectRow(0);
                        }
                    }

                    Loading(false);
                });
            });
        }
コード例 #28
0
 private void FillReferenceColumnSelector(TreeIter iter, string table)
 {
     if (tables.Contains(table))
     {
         refTable = tables.Search(table);
         if (refTable != null)
         {
             referenceColumnSelecter.Initialize(refTable.Columns);
             referenceColumnSelecter.Sensitive = true;
             store.SetValue(iter, colReferenceTableIndex, table);
             SetSelectionFromIter(iter);
         }
         else
         {
             referenceColumnSelecter.Sensitive = false;
             referenceColumnSelecter.Clear();
         }
         EmitContentChanged();
     }
 }
コード例 #29
0
        private void LoadImages()
        {
            string directoryName = "/usr/share/pixmaps/meshwork/avatars";

            if (Directory.Exists(directoryName) == true)
            {
                foreach (FileInfo file in new DirectoryInfo(directoryName).GetFiles())
                {
                    Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(file.FullName);

                    if (pixbuf.Width > 80 | pixbuf.Height > 80)
                    {
                        pixbuf = pixbuf.ScaleSimple(80, 80, Gdk.InterpType.Hyper);
                    }

                    Gtk.Application.Invoke(delegate {
                        TreeIter iter = store.Insert(0);
                        store.SetValue(iter, 0, pixbuf);
                        store.SetValue(iter, 1, file.FullName);
                    });
                }
            }


            // Load gravatar... timeout after a few seconds
            Thread timeoutThread = new Thread(new ThreadStart(TimeoutGravatar));

            timeoutThread.Start();

            string hash = "b653c99616e34ee4f834da53b109ce01";

            WebClient client = new WebClient();

            try {
                byte[] data = client.DownloadData(String.Format("http://www.gravatar.com/avatar.php?gravatar_id={0}", hash));
                Application.Invoke(delegate { GotGravatarImage(data); });
            } catch (Exception ex) {
                LoggingService.LogError(ex);
                Application.Invoke(delegate { GotGravatarImage(null); });
            }
        }
コード例 #30
0
        private void DrawAssets()
        {
            var selectedProject = _selectProjectsComboBox.SelectedItem;
            var selectedResult  = _selectResultComboBox.SelectedText;

            _resultsStore.Clear();
            foreach (AssetProperties asset in this.assets)
            {
                if (selectedProject is Project project && asset.Project != project)
                {
                    continue;
                }
                if (selectedResult == "Not analyzed" && asset.Result.Value != null)
                {
                    continue;
                }
                if (selectedResult == "OK" && (asset.Result.Value != null && asset.Result.IsError || asset.Result.Value == null))
                {
                    continue;
                }
                if (selectedResult == "Failed" && (asset.Result.Value != null && asset.Result.IsSuccess || asset.Result.Value == null))
                {
                    continue;
                }

                var row = _resultsStore.AddRow();
                _resultsStore.SetValue(row, _assetProperties, asset);
                _resultsStore.SetValue(row, _imageFileNameField, asset.Asset.Identifier);
                _resultsStore.SetValue(row, _projectNameField, asset.Project.Name);
                if (asset.Result.Value == null)
                {
                    _resultsStore.SetValue(row, _resultField, "Not analyzed");
                }
                else
                {
                    _resultsStore.SetValue(row, _resultField, asset.Result.IsSuccess ? "OK" : "Failed");
                }
            }
        }
コード例 #31
0
        public ExtractInterfaceDialog()
        {
            this.Build();
            this.buttonSelectAll.Clicked += delegate {
                for (int i = 0; i < treeStore.RowCount; i++)
                {
                    treeStore.SetValue(i, symbolIncludedField, true);
                }
                UpdateOkButton();
            };

            this.buttonDeselectAll.Clicked += delegate {
                for (int i = 0; i < treeStore.RowCount; i++)
                {
                    treeStore.SetValue(i, symbolIncludedField, false);
                }
                UpdateOkButton();
            };

            listViewPublicMembers.HeadersVisible = false;
            listViewPublicMembers.DataSource     = treeStore;
            var checkBoxCellView = new CheckBoxCellView(symbolIncludedField);

            checkBoxCellView.Editable = true;
            checkBoxCellView.Toggled += delegate {
                GLib.Timeout.Add(20, delegate {
                    UpdateOkButton();
                    return(false);
                });
            };
            listViewPublicMembers.Columns.Add("", checkBoxCellView);
            listViewPublicMembers.Columns.Add("", new ImageCellView(symbolIconField), new TextCellView(symbolTextField));


            this.entryName.Changed     += delegate { UpdateOkButton(); };
            this.entryFileName.Changed += delegate { UpdateOkButton(); };
        }
コード例 #32
0
		public SinglePlayerView(LauncherWindow window)
		{
			Worlds.Local = new Worlds();
			Worlds.Local.Load();

			Window = window;
			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.InteractionBox.Remove(this);
				Window.InteractionBox.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);

			PackStart(SinglePlayerLabel);
			PackStart(WorldListView);
			PackStart(createDeleteHbox);
			PackStart(PlayButton);
			PackStart(CreateWorldBox);
			PackStart(ProgressLabel);
			PackStart(ProgressBar);
			PackEnd(BackButton);
		}
コード例 #33
0
ファイル: ListView1.cs プロジェクト: b-theile/xwt
        public ListView1()
        {
            PackStart(new Label("The listview should have a red background"));
            ListView list = new ListView();

            list.GridLinesVisible = GridLines.Both;
            ListStore store = new ListStore(name, icon, text, icon2, progress);

            list.DataSource = store;
            list.Columns.Add("Name", icon, name);
            list.Columns.Add("Text", icon2, text);
            list.Columns.Add("Progress", new TextCellView()
            {
                TextField = text
            }, new CustomCell()
            {
                ValueField = progress
            });

            var png = Image.FromResource(typeof(App), "class.png");

            Random rand = new Random();

            for (int n = 0; n < 100; n++)
            {
                var r = store.AddRow();
                store.SetValue(r, icon, png);
                store.SetValue(r, name, "Value " + n);
                store.SetValue(r, icon2, png);
                store.SetValue(r, text, "Text " + n);
                store.SetValue(r, progress, new CellData {
                    Value = rand.Next() % 100
                });
            }
            PackStart(list, true);

            list.RowActivated += delegate(object sender, ListViewRowEventArgs e) {
                MessageDialog.ShowMessage("Row " + e.RowIndex + " activated");
            };

            Menu contextMenu = new Menu();

            contextMenu.Items.Add(new MenuItem("Test menu"));
            list.ButtonPressed += delegate(object sender, ButtonEventArgs e) {
                int row = list.GetRowAtPosition(new Point(e.X, e.Y));
                if (e.Button == PointerButton.Right && row >= 0)
                {
                    // Set actual row to selected
                    list.SelectRow(row);
                    contextMenu.Popup(list, e.X, e.Y);
                }
            };

            var but = new Button("Scroll one line");

            but.Clicked += delegate {
                list.VerticalScrollControl.Value += list.VerticalScrollControl.StepIncrement;
            };
            PackStart(but);

            var spnValue = new SpinButton();

            spnValue.MinimumValue   = 0;
            spnValue.MaximumValue   = 99;
            spnValue.IncrementValue = 1;
            spnValue.Digits         = 0;
            var btnScroll = new Button("Go!");

            btnScroll.Clicked += (sender, e) => list.ScrollToRow((int)spnValue.Value);

            HBox scrollActBox = new HBox();

            scrollActBox.PackStart(new Label("Scroll to Value: "));
            scrollActBox.PackStart(spnValue);
            scrollActBox.PackStart(btnScroll);
            PackStart(scrollActBox);
        }
コード例 #34
0
ファイル: StackTracePad.cs プロジェクト: t9up/monodevelop
        void Update()
        {
            if (tree.IsRealized)
            {
                tree.ScrollToPoint(0, 0);
            }

            needsUpdate = false;
            store.Clear();

            if (!DebuggingService.IsPaused)
            {
                return;
            }

            var backtrace        = DebuggingService.CurrentCallStack;
            var externalCodeIter = TreeIter.Zero;

            for (int i = 0; i < backtrace.FrameCount; i++)
            {
                bool icon = i == DebuggingService.CurrentFrameIndex;

                StackFrame frame = backtrace.GetFrame(i);
                if (frame.IsDebuggerHidden)
                {
                    continue;
                }

                if (!ShowExternalCode && frame.IsExternalCode)
                {
                    if (externalCodeIter.Equals(TreeIter.Zero))
                    {
                        externalCodeIter = store.AppendValues(icon, GettextCatalog.GetString("[External Code]"), string.Empty, string.Empty, string.Empty, null, Pango.Style.Italic, null, -1);
                    }
                    else if (icon)
                    {
                        //Set IconColumn value to true if any of hidden frames is current frame
                        store.SetValue(externalCodeIter, IconColumn, true);
                    }
                    continue;
                }
                externalCodeIter = TreeIter.Zero;
                var method = EvaluateMethodName(frame);

                string file;
                if (!string.IsNullOrEmpty(frame.SourceLocation.FileName))
                {
                    file = frame.SourceLocation.FileName;
                    if (frame.SourceLocation.Line != -1 && ShowLineNumber)
                    {
                        file += ":" + frame.SourceLocation.Line;
                    }
                }
                else
                {
                    file = string.Empty;
                }

                var style = frame.IsExternalCode ? Pango.Style.Italic : Pango.Style.Normal;

                store.AppendValues(icon, method, file, frame.Language, "0x" + frame.Address.ToString("x"), null,
                                   style, frame, i);
            }
        }
コード例 #35
0
        public MainWindow()
        {
            XML gxml = new XML(null, "MultiMC.GTKGUI.MainWindow.glade",
                               "mainVBox", null);

            gxml.Toplevel = this;
            gxml.Autoconnect(this);

            XML gxml2 = new XML(null, "MultiMC.GTKGUI.InstContextMenu.glade",
                                "instContextMenu", null);

            gxml2.Autoconnect(this);

            /*
             * HACK: the nested menu isn't picked up by the first gxml object. It is probably a GTK# bug.
             * This is the fix - manually asking for the menu and connecting it.
             */
            XML gxml3 = new XML(null, "MultiMC.GTKGUI.MainWindow.glade",
                                "menunew", null);

            gxml3.Autoconnect(this);
            newInstButton.Menu = menunew;

            this.Add(mainVBox);

            ShowAll();

            this.WidthRequest  = 620;
            this.HeightRequest = 380;

            DeleteEvent += (o, args) => Application.Quit();

            // Set up the instance icon view
            instListStore = new ListStore(
                typeof(string), typeof(Gdk.Pixbuf), typeof(Instance));

            instView.Model        = instListStore;
            instView.TextColumn   = 0;
            instView.PixbufColumn = 1;
            instView.ItemWidth    = -1;

            Gtk.CellRendererText crt = instView.Cells[0] as CellRendererText;
            crt.Editable = true;
            crt.Edited  += (object o, EditedArgs args) =>
            {
                int      EditedIndex = int.Parse(args.Path);
                TreeIter iter;
                // don't allow bad names
                if (!Instance.NameIsValid(args.NewText))
                {
                    return;
                }
                System.Console.WriteLine("Path: " + args.Path + " New text: " + args.NewText);
                if (instListStore.GetIterFromString(out iter, args.Path))
                {
                    instListStore.SetValue(iter, 0, args.NewText);
                    Instance inst = instListStore.GetValue(iter, 2) as Instance;
                    inst.Name = args.NewText;
                }
            };

            instView.Orientation       = Orientation.Vertical;
            instView.ButtonPressEvent += (o, args) =>
            {
                if (args.Event.Button == 3 &&
                    instView.GetPathAtPos((int)args.Event.X,
                                          (int)args.Event.Y) != null)
                {
                    instView.SelectPath(instView.GetPathAtPos(
                                            (int)args.Event.X, (int)args.Event.Y));
                    instContextMenu.Popup();
                }
            };
            instView.KeyPressEvent += (object o, KeyPressEventArgs args) =>
            {
                if (args.Event.Key == Gdk.Key.F2)
                {
                    if (instView.SelectedItems.Count() != 0)
                    {
                        instView.SetCursor(instView.SelectedItems[0], instView.Cells[0], true);
                    }
                }
                else if (args.Event.Key == Gdk.Key.Escape)
                {
                    if (EscPressed != null)
                    {
                        EscPressed(this, EventArgs.Empty);
                    }
                }
            };

            // Set up the task list
            EventfulList <Task> tList = new EventfulList <Task>();

            tList.Added   += TaskAdded;
            tList.Removed += TaskRemoved;

            TaskList     = tList;
            taskProgBars = new Dictionary <int, Box>();

            // Set up the instance list
            EventfulList <Instance> iList = new EventfulList <Instance>();

            iList.Added   += InstAdded;
            iList.Removed += InstRemoved;

            InstanceList = iList;

            helpButton.Sensitive = false;
            if (OSUtils.OS == OSEnum.Linux)
            {
                Gtk.MenuItem openalRemoveItem = gxml2.GetWidget("removeOpenALMenuItem") as Gtk.MenuItem;
                openalRemoveItem.Visible = true;
            }
        }
コード例 #36
0
ファイル: ListViewCellBounds.cs プロジェクト: m13253/xwt
		public ListViewCellBounds ()
		{
			MinHeight = 120;
			MinWidth = 100;

			container = new VBox ();
			ListView = new ListView();

			ListView.GridLinesVisible = GridLines.Both;
			ListStore = new ListStore (name, icon, text, check, progress);
			ListView.DataSource = ListStore;
			ListView.Columns.Add ("Name", icon, name);
			ListView.Columns.Add ("Check", new TextCellView () { TextField = text }, new CustomCell () { ValueField = progress, Size = new Size(20, 20) }, new CheckBoxCellView() { ActiveField = check });
			//list.Columns.Add ("Progress", new TextCellView () { TextField = text }, new CustomCell () { ValueField = progress }, new TextCellView () { TextField = text } );
			ListView.Columns.Add ("Progress", new CustomCell () { ValueField = progress });

			var png = Image.FromResource (typeof(App), "class.png");

			Random rand = new Random ();

			for (int n=0; n<100; n++) {
				var r = ListStore.AddRow ();
				ListStore.SetValue (r, icon, png);
				if (rand.Next (50) > 25) {
					ListStore.SetValue (r, name, "Value \n" + n);
					ListStore.SetValue (r, check, false);
				} else {
					ListStore.SetValue (r, name, "Value " + n);
					ListStore.SetValue (r, check, true);
				}
				ListStore.SetValue (r, text, "Text " + n);
				ListStore.SetValue (r, progress, new CellData { Value = rand.Next () % 100 });
			}

			ListView.SelectionChanged += (sender, e) => UpdateTracker (ListView.SelectedRow);
			ListView.MouseMoved += (sender, e) => UpdateTracker (ListView.GetRowAtPosition (e.X, e.Y));

			drawer = new ListTrackingCanvas (this);

			container.PackStart (ListView, true);
			container.PackStart (drawer);
			AddChild (container);
		}
コード例 #37
0
ファイル: ListView.cs プロジェクト: eliog/hamekoz-sharp
        public void FillRow(int row, T item)
        {
            foreach (var column in Columns)
            {
                var field        = datafields [Columns.IndexOf(column)];
                var propertyName = column.Title.Dehumanize();
                var property     = type.GetProperty(propertyName);
                switch (Type.GetTypeCode(property.PropertyType))
                {
                case TypeCode.Int32:
                    if (property.PropertyType.IsEnum)
                    {
                        var value = property.GetValue(item, null);
                        store.SetValue(row, (IDataField <string>)field, ((Enum)value).Humanize());
                    }
                    else
                    {
                        store.SetValue <string> (row, (IDataField <string>)field, string.Format("{0:D}", (int)property.GetValue(item, null)));
                    }
                    break;

                case TypeCode.Double:
                    store.SetValue <string> (row, (IDataField <string>)field, string.Format("{0:#0.######}", (double)property.GetValue(item, null)));
                    break;

                case TypeCode.Decimal:
                    store.SetValue <string> (row, (IDataField <string>)field, string.Format("{0:N}", (decimal)property.GetValue(item, null)));
                    break;

                case TypeCode.Boolean:
                    store.SetValue <bool> (row, (IDataField <bool>)field, (bool)property.GetValue(item, null));
                    break;

                case TypeCode.DateTime:
                    var    date       = (DateTime)property.GetValue(item, null);
                    string dateString = date == date.Date ? date.ToShortDateString() : date.ToString();
                    store.SetValue <string> (row, (IDataField <string>)field, dateString);
                    break;

                case TypeCode.String:
                    store.SetValue <string> (row, (IDataField <string>)field, (string)property.GetValue(item, null));
                    break;

                default:
                    if (property.PropertyType == typeof(DateTime?))
                    {
                        var    datenull       = (DateTime?)property.GetValue(item, null);
                        string datenullString = datenull.HasValue ? (datenull.Value == datenull.Value.Date ? datenull.Value.ToShortDateString() : datenull.ToString()) : string.Empty;
                        store.SetValue <string> (row, (IDataField <string>)field, datenullString);
                        break;
                    }
                    else
                    {
                        object value;
                        try {
                            value = property.GetValue(item, null);
                        } catch (Exception) {
                            value = string.Empty;
                        }
                        store.SetValue(row, (IDataField <object>)field, value);
                        break;
                    }
                }
                store.SetValue(row, itemDataField, item);
            }
        }
コード例 #38
0
        public override void LaunchDialogue()
        {
            //the Type in the collection
            IList  collection  = (IList)Value;
            string displayName = Inspector.DisplayName;

            //populate list with existing items
            ListStore itemStore = new ListStore(typeof(object), typeof(int), typeof(string));

            for (int i = 0; i < collection.Count; i++)
            {
                itemStore.AppendValues(collection [i], i, collection [i].ToString());
            }

            #region Building Dialogue

            TreeView      itemTree;
            InspectorGrid grid;
            TreeIter      previousIter = TreeIter.Zero;

            //dialogue and buttons
            Dialog dialog = new Dialog()
            {
                Title       = displayName + " Editor",
                Modal       = true,
                AllowGrow   = true,
                AllowShrink = true,
            };
            var toplevel = this.Container.Toplevel as Window;
            if (toplevel != null)
            {
                dialog.TransientFor = toplevel;
            }

            dialog.AddActionWidget(new Button(Stock.Cancel), ResponseType.Cancel);
            dialog.AddActionWidget(new Button(Stock.Ok), ResponseType.Ok);

            //three columns for items, sorting, PropGrid
            HBox hBox = new HBox();
            dialog.VBox.PackStart(hBox, true, true, 5);

            //propGrid at end
            grid = new InspectorGrid(base.EditorManager)
            {
                CurrentObject = null,
                WidthRequest  = 200,
                ShowHelp      = false
            };
            hBox.PackEnd(grid, true, true, 5);

            //followed by a ButtonBox
            VBox buttonBox = new VBox();
            buttonBox.Spacing = 6;
            hBox.PackEnd(buttonBox, false, false, 5);

            //add/remove buttons
            Button addButton = new Button(new Image(Stock.Add, IconSize.Button));
            buttonBox.PackStart(addButton, false, false, 0);
            if (types [0].IsAbstract)
            {
                addButton.Sensitive = false;
            }
            Button removeButton = new Button(new Gtk.Image(Stock.Remove, IconSize.Button));
            buttonBox.PackStart(removeButton, false, false, 0);

            //sorting buttons
            Button upButton = new Button(new Image(Stock.GoUp, IconSize.Button));
            buttonBox.PackStart(upButton, false, false, 0);
            Button downButton = new Button(new Image(Stock.GoDown, IconSize.Button));
            buttonBox.PackStart(downButton, false, false, 0);

            //Third column has list(TreeView) in a ScrolledWindow
            ScrolledWindow listScroll = new ScrolledWindow();
            listScroll.WidthRequest  = 200;
            listScroll.HeightRequest = 320;
            hBox.PackStart(listScroll, false, false, 5);

            itemTree = new TreeView(itemStore);
            itemTree.Selection.Mode = SelectionMode.Single;
            itemTree.HeadersVisible = false;
            listScroll.AddWithViewport(itemTree);

            //renderers and attribs for TreeView
            CellRenderer rdr = new CellRendererText();
            itemTree.AppendColumn(new TreeViewColumn("Index", rdr, "text", 1));
            rdr = new CellRendererText();
            itemTree.AppendColumn(new TreeViewColumn("Object", rdr, "text", 2));

            #endregion

            #region Events

            addButton.Clicked += delegate {
                //create the object
                object instance = System.Activator.CreateInstance(types[0]);

                //get existing selection and insert after it
                TreeIter oldIter, newIter;
                if (itemTree.Selection.GetSelected(out oldIter))
                {
                    newIter = itemStore.InsertAfter(oldIter);
                }
                //or append if no previous selection
                else
                {
                    newIter = itemStore.Append();
                }
                itemStore.SetValue(newIter, 0, instance);

                //select, set name and update all the indices
                itemTree.Selection.SelectIter(newIter);
                UpdateName(itemStore, newIter);
                UpdateIndices(itemStore);
            };

            removeButton.Clicked += delegate {
                //get selected iter and the replacement selection
                TreeIter iter, newSelection;
                if (!itemTree.Selection.GetSelected(out iter))
                {
                    return;
                }

                newSelection = iter;
                if (!IterPrev(itemStore, ref newSelection))
                {
                    newSelection = iter;
                    if (!itemStore.IterNext(ref newSelection))
                    {
                        newSelection = TreeIter.Zero;
                    }
                }

                //new selection. Zeroing previousIter prevents trying to update name of deleted iter.
                previousIter = TreeIter.Zero;
                if (itemStore.IterIsValid(newSelection))
                {
                    itemTree.Selection.SelectIter(newSelection);
                }

                //and the removal and index update
                itemStore.Remove(ref iter);
                UpdateIndices(itemStore);
            };

            upButton.Clicked += delegate {
                TreeIter iter, prev;
                if (!itemTree.Selection.GetSelected(out iter))
                {
                    return;
                }

                //get previous iter
                prev = iter;
                if (!IterPrev(itemStore, ref prev))
                {
                    return;
                }

                //swap the two
                itemStore.Swap(iter, prev);

                //swap indices too
                object prevVal = itemStore.GetValue(prev, 1);
                object iterVal = itemStore.GetValue(iter, 1);
                itemStore.SetValue(prev, 1, iterVal);
                itemStore.SetValue(iter, 1, prevVal);
            };

            downButton.Clicked += delegate {
                TreeIter iter, next;
                if (!itemTree.Selection.GetSelected(out iter))
                {
                    return;
                }

                //get next iter
                next = iter;
                if (!itemStore.IterNext(ref next))
                {
                    return;
                }

                //swap the two
                itemStore.Swap(iter, next);

                //swap indices too
                object nextVal = itemStore.GetValue(next, 1);
                object iterVal = itemStore.GetValue(iter, 1);
                itemStore.SetValue(next, 1, iterVal);
                itemStore.SetValue(iter, 1, nextVal);
            };

            itemTree.Selection.Changed += delegate {
                TreeIter iter;
                if (!itemTree.Selection.GetSelected(out iter))
                {
                    removeButton.Sensitive = false;
                    return;
                }
                removeButton.Sensitive = true;

                //update grid
                object obj = itemStore.GetValue(iter, 0);
                grid.CurrentObject = obj;

                //update previously selected iter's name
                UpdateName(itemStore, previousIter);

                //update current selection so we can update
                //name next selection change
                previousIter = iter;
            };

            grid.Changed += delegate {
                TreeIter iter;
                if (itemTree.Selection.GetSelected(out iter))
                {
                    UpdateName(itemStore, iter);
                }
            };

            TreeIter selectionIter;
            removeButton.Sensitive = itemTree.Selection.GetSelected(out selectionIter);

            dialog.ShowAll();
            grid.ShowToolbar = false;

            #endregion

            //if 'OK' put items back in collection
            if (GtkExtensions.ShowCustomDialog(dialog, toplevel) == (int)ResponseType.Ok)
            {
                DesignerTransaction tran = CreateTransaction(Instance);
                object old = collection;

                try {
                    collection.Clear();
                    foreach (object[] o in itemStore)
                    {
                        collection.Add(o[0]);
                    }
                    EndTransaction(Instance, tran, old, collection, true);
                }
                catch {
                    EndTransaction(Instance, tran, old, collection, false);
                    throw;
                }
            }
        }
コード例 #39
0
        private void OnConnectionEdited(object sender, DatabaseConnectionContextEventArgs args)
        {
            TreeIter iter = GetTreeIter(args.ConnectionContext);

            store.SetValue(iter, 0, args.ConnectionContext.ConnectionSettings.Name);
        }
コード例 #40
0
ファイル: ListBox.cs プロジェクト: sergueik/xwt_swd
        public ListBoxSample()
        {
            // Default list box

            ListBox list = new ListBox();

            for (int n = 0; n < 100; n++)
                list.Items.Add("Value " + n);

            list.KeyPressed += (sender, e) =>
            {
                if (e.Key == Key.Insert)
                {
                    int r = list.SelectedRow + 1;
                    list.Items.Insert(r, "Value " + list.Items.Count + 1);
                    list.ScrollToRow(r);
                    list.SelectRow(r);
                    list.FocusedRow = r;
                }
            };

            PackStart(list, true);

            // Custom list box

            ListBox customList = new ListBox();
            customList.GridLinesVisible = true;
            ListStore store = new ListStore(name, icon);
            customList.DataSource = store;
            customList.Views.Add(new ImageCellView(icon));
            customList.Views.Add(new TextCellView(name));

            var png = Image.FromResource(typeof(Application), "class.png");

            for (int n = 0; n < 100; n++)
            {
                var r = store.AddRow();
                store.SetValue(r, icon, png);
                store.SetValue(r, name, "Value " + n);
            }

            customList.KeyPressed += (sender, e) =>
            {
                if (e.Key == Key.Insert)
                {
                    var r = store.InsertRowAfter(customList.SelectedRow < 0 ? 0 : customList.SelectedRow);
                    store.SetValue(r, icon, png);
                    store.SetValue(r, name, "Value " + (store.RowCount + 1));
                    customList.ScrollToRow(r);
                    customList.SelectRow(r);
                    customList.FocusedRow = r;
                }
            };

            PackStart(customList, true);

            var spnValue = new SpinButton();
            spnValue.MinimumValue = 0;
            spnValue.MaximumValue = 99;
            spnValue.IncrementValue = 1;
            spnValue.Digits = 0;
            var btnScroll = new Button("Go!");
            btnScroll.Clicked += (sender, e) => customList.ScrollToRow((int)spnValue.Value);

            HBox scrollActBox = new HBox();
            scrollActBox.PackStart(new Label("Scroll to Value: "));
            scrollActBox.PackStart(spnValue);
            scrollActBox.PackStart(btnScroll);
            PackStart(scrollActBox);
        }
コード例 #41
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #42
0
ファイル: ComboBoxes.cs プロジェクト: StEvUgnIn/xwt
		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);
		}
コード例 #43
0
ファイル: OrderDlg.cs プロジェクト: QualitySolution/CarGlass
        void OnCostSpinEdited(object o, EditedArgs args)
        {
            TreeIter iter;

            if (!ServiceListStore.GetIterFromString(out iter, args.Path))
            {
                return;
            }
            double Cost;

            if (double.TryParse(args.NewText, out Cost))
            {
                ServiceListStore.SetValue(iter, 3, Cost);
                CalculateTotal();
            }
        }
コード例 #44
0
ファイル: ComboBoxes.cs プロジェクト: pabloescribano/xwt
        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);
        }
コード例 #45
0
        private void GenerateNotebookPages()
        {
            string platformName = MainClass.Settings.Platform.Name;

            foreach (Rule rl in MainClass.Settings.Platform.Rules)
            {
                bool iOsNoMac = false;

                if ((rl.Tag == -1) && !MainClass.Settings.ShowUnsupportedDevices)
                {
                    continue;
                }
                if ((rl.Tag == -2) && !MainClass.Settings.ShowDebugDevices)
                {
                    continue;
                }

                bool validDevice = true;

                if (!Device.CheckDevice(rl.Specific))
                {
                    Tool.Logger.Debug("Invalid Device " + rl.Specific);
                    validDevice = false;
                }

                ScrolledWindow sw = new ScrolledWindow();
                sw.ShadowType = ShadowType.EtchedOut;

                TreeView tvList = new TreeView();

                List <CombinePublish> lcp        = project.ProjectUserSetting.CombinePublish.FindAll(x => x.combineRule.FindIndex(y => y.ConditionName == platformName && y.RuleId == rl.Id) > -1);
                List <CombinePublish> lcpDennied = new List <CombinePublish>();
                string deviceName = rl.Name;
                int    deviceTyp  = rl.Id;

                ListStore ls = new ListStore(typeof(bool), typeof(string), typeof(CombinePublish), typeof(string), typeof(bool));

                string ico = "empty.png";
                switch (deviceTyp)
                {
                case (int)DeviceType.Android_1_6: {
                    ico = "android.png";
                    break;
                }

                case (int)DeviceType.Android_2_2: {
                    ico = "android.png";
                    break;
                }

                case (int)DeviceType.Bada_1_0:
                case (int)DeviceType.Bada_1_1:
                case (int)DeviceType.Bada_1_2:
                case (int)DeviceType.Bada_2_0: {
                    ico = "bada.png";
                    break;
                }

                case (int)DeviceType.Symbian_9_4: {
                    ico = "symbian.png";
                    break;
                }

                case (int)DeviceType.iOS_5_0: {
                    ico = "apple.png";
                    if (!MainClass.Platform.IsMac)
                    {
                        iOsNoMac = true;
                    }

                    break;
                }

                case (int)DeviceType.PocketPC_2003SE:
                case (int)DeviceType.WindowsMobile_5:
                case (int)DeviceType.WindowsMobile_6: {
                    ico = "windows.png";
                    break;
                }

                case (int)DeviceType.Windows: {
                    ico = "win32.png";
                    break;
                }

                case (int)DeviceType.MacOs: {
                    ico = "macos.png";
                    break;
                }
                }

                List <CombinePublish> tmp = lcp.FindAll(x => x.IsSelected == true);

                NotebookLabel nl = new NotebookLabel(ico, String.Format("{0} ({1})", deviceName, tmp.Count));
                nl.Tag = deviceTyp;


                if (iOsNoMac)
                {
                    Label lbl = new Label(MainClass.Languages.Translate("ios_available_Mac"));

                    Pango.FontDescription customFont = Pango.FontDescription.FromString(MainClass.Settings.ConsoleTaskFont);
                    customFont.Weight = Pango.Weight.Bold;
                    lbl.ModifyFont(customFont);

                    notebook.AppendPage(lbl, nl);
                    continue;
                }
                if (!validDevice)
                {
                    Label lbl = new Label(MainClass.Languages.Translate("publish_tool_missing"));

                    Pango.FontDescription customFont = Pango.FontDescription.FromString(MainClass.Settings.ConsoleTaskFont);
                    customFont.Weight = Pango.Weight.Bold;
                    lbl.ModifyFont(customFont);

                    notebook.AppendPage(lbl, nl);
                    continue;
                }

                ;
                CellRendererToggle crt = new CellRendererToggle();
                crt.Activatable = true;
                crt.Sensitive   = true;
                tvList.AppendColumn("", crt, "active", 0);

                Gtk.CellRendererText fileNameRenderer     = new Gtk.CellRendererText();
                Gtk.CellRendererText collumnResolRenderer = new Gtk.CellRendererText();

                tvList.AppendColumn(MainClass.Languages.Translate("file_name"), fileNameRenderer, "text", 1);
                tvList.AppendColumn(MainClass.Languages.Translate("resolution_f1"), collumnResolRenderer, "text", 1);

                tvList.Columns[1].SetCellDataFunc(fileNameRenderer, new Gtk.TreeCellDataFunc(RenderCombine));
                tvList.Columns[2].SetCellDataFunc(collumnResolRenderer, new Gtk.TreeCellDataFunc(RenderResolution));

                // povolene resolution pre danu platformu
                PlatformResolution listPR = MainClass.Settings.PlatformResolutions.Find(x => x.IdPlatform == deviceTyp);

                Device dvc = project.DevicesSettings.Find(x => x.TargetPlatformId == deviceTyp);

                string stringTheme = "";
                List <System.IO.DirectoryInfo> themeResolution = new List <System.IO.DirectoryInfo>();               // resolution z adresara themes po novom

                if ((project.NewSkin) && (dvc != null))
                {
                    Skin skin = dvc.Includes.Skin;
                    if ((skin != null) && (!String.IsNullOrEmpty(skin.Name)) && (!String.IsNullOrEmpty(skin.Theme)))
                    {
                        string skinDir = System.IO.Path.Combine(MainClass.Workspace.RootDirectory, MainClass.Settings.SkinDir);
                        stringTheme = System.IO.Path.Combine(skinDir, skin.Name);
                        stringTheme = System.IO.Path.Combine(stringTheme, "themes");
                        stringTheme = System.IO.Path.Combine(stringTheme, skin.Theme);

                        if (System.IO.Directory.Exists(stringTheme))
                        {
                            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(stringTheme);
                            themeResolution = new List <System.IO.DirectoryInfo>(di.GetDirectories());
                        }
                    }
                }

                crt.Toggled += delegate(object o, ToggledArgs args) {
                    if ((deviceTyp == (int)DeviceType.Windows) || (deviceTyp == (int)DeviceType.MacOs))
                    {
                        if (!MainClass.LicencesSystem.CheckFunction("windowsandmac", this))
                        {
                            return;
                        }
                    }


                    TreeIter iter;
                    if (ls.GetIter(out iter, new TreePath(args.Path)))
                    {
                        bool           old = (bool)ls.GetValue(iter, 0);
                        CombinePublish cp  = (CombinePublish)ls.GetValue(iter, 2);
                        cp.IsSelected = !old;
                        ls.SetValue(iter, 0, !old);

                        List <CombinePublish> tmp2 = lcp.FindAll(x => x.IsSelected == true);
                        nl.SetLabel(String.Format("{0} ({1})", deviceName, tmp2.Count));

                        //if(dvc == null) return;
                        //if(dvc.Includes == null) return;
                        if (dvc.Includes.Skin == null)
                        {
                            return;
                        }
                        if (String.IsNullOrEmpty(dvc.Includes.Skin.Name) || String.IsNullOrEmpty(dvc.Includes.Skin.Theme))
                        {
                            return;
                        }


                        if (cp.IsSelected)
                        {
                            // Najdem ake je rozlisenie v danej combinacii
                            CombineCondition cc = cp.combineRule.Find(x => x.ConditionId == MainClass.Settings.Resolution.Id);

                            if (cc == null)
                            {
                                return;                                        /// nema ziadne rozlisenie v combinacii
                            }
                            int indxResol = themeResolution.FindIndex(x => x.Name.ToLower() == cc.RuleName.ToLower());
                            if (indxResol < 0)
                            {
                                // theme chyba prislusne rozlisenie
                                string error = String.Format("Invalid {0} Skin and {1} Theme, using in {2}. Missing resolutions: {3}. ", dvc.Includes.Skin.Name, dvc.Includes.Skin.Theme, deviceName, cc.RuleName.ToLower());
                                MainClass.MainWindow.OutputConsole.WriteError(error + "\n");
                                List <string> lst = new List <string>();
                                lst.Add(error);
                                MainClass.MainWindow.ErrorWritte("", "", lst);
                            }
                        }
                    }
                };

                int cntOfAdded = 0;
                foreach (CombinePublish cp in lcp)
                {
                    bool isValid = cp.IsSelected;

                    if (!validDevice)
                    {
                        isValid = false;
                    }

                    // Najdem ake je rozlisenie v danej combinacii
                    CombineCondition cc = cp.combineRule.Find(x => x.ConditionId == MainClass.Settings.Resolution.Id);

                    if (cc == null)
                    {
                        continue;                                /// nema ziadne rozlisenie v combinacii
                    }
                    int indx = MainClass.Settings.Resolution.Rules.FindIndex(x => x.Id == cc.RuleId);
                    if (indx < 0)
                    {
                        continue;                            /// rozlisenie pouzite v danej combinacii nexistuje
                    }
                    if (cc != null)
                    {
                        bool isValidResolution = false;

                        //ak nema definovane ziadne povolenia, tak povolene su vsetky
                        if ((listPR == null) || (listPR.AllowResolution == null) ||
                            (listPR.AllowResolution.Count < 1))
                        {
                            isValidResolution = true;
                        }
                        else
                        {
                            isValidResolution = listPR.IsValidResolution(cc.RuleId);
                        }

                        if (isValidResolution)
                        {
                            // po novom vyhodom aj tie ktore niesu v adresaru themes - pokial je thema definovana
                            if ((project.NewSkin) && (themeResolution.Count > 0))
                            {
                                //cntResolution = 0;
                                int indxResol = themeResolution.FindIndex(x => x.Name.ToLower() == cc.RuleName.ToLower());
                                if (indxResol > -1)
                                {
                                    ls.AppendValues(isValid, cp.ProjectName, cp, cp.ProjectName, true);
                                    cntOfAdded++;
                                }
                                else
                                {
                                    lcpDennied.Add(cp);
                                }
                            }
                            else
                            {
                                ls.AppendValues(isValid, cp.ProjectName, cp, cp.ProjectName, true);
                                cntOfAdded++;
                            }
                        }
                        else
                        {
                            lcpDennied.Add(cp);
                        }
                    }
                    //}
                }
                // pridam tie zakazane, ktore su vybrate na publish
                foreach (CombinePublish cp in lcpDennied)
                {
                    if (cp.IsSelected)
                    {
                        ls.AppendValues(cp.IsSelected, cp.ProjectName, cp, cp.ProjectName, false);
                        cntOfAdded++;
                    }
                }

                if (cntOfAdded == 0)
                {
                    MainClass.MainWindow.OutputConsole.WriteError(String.Format("Missing publish settings for {0}.\n", deviceName));
                }

                bool showAll = false;
                tvList.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args){
                    if (args.Event.Button == 3)
                    {
                        TreeSelection  ts     = tvList.Selection;
                        Gtk.TreePath[] selRow = ts.GetSelectedRows();

                        if (selRow.Length < 1)
                        {
                            TreeIter tiFirst = new TreeIter();
                            ls.GetIterFirst(out tiFirst);

                            tvList.Selection.SelectIter(tiFirst);
                            selRow = ts.GetSelectedRows();
                        }
                        if (selRow.Length < 1)
                        {
                            return;
                        }

                        Gtk.TreePath tp = selRow[0];
                        TreeIter     ti = new TreeIter();

                        ls.GetIter(out ti, tp);

                        CombinePublish combinePublish = (CombinePublish)ls.GetValue(ti, 2);

                        if (combinePublish != null)
                        {
                            Menu popupMenu = new Menu();
                            if (!showAll)
                            {
                                MenuItem miShowDenied = new MenuItem(MainClass.Languages.Translate("show_denied"));
                                miShowDenied.Activated += delegate(object sender, EventArgs e) {
                                    // odoberem zakazane, ktore sa zobrazuju kedze su zaceknute na publish
                                    List <TreeIter> lst = new List <TreeIter>();
                                    ls.Foreach((model, path, iterr) => {
                                        bool cp       = (bool)ls.GetValue(iterr, 4);
                                        bool selected = (bool)ls.GetValue(iterr, 0);
                                        if (!cp && selected)
                                        {
                                            lst.Add(iterr);
                                        }
                                        return(false);
                                    });

                                    foreach (TreeIter ti2 in lst)
                                    {
                                        TreeIter ti3 = ti2;
                                        ls.Remove(ref ti3);
                                    }

                                    // pridam zakazane
                                    if ((lcpDennied == null) || (lcpDennied.Count < 1))
                                    {
                                        return;
                                    }

                                    foreach (CombinePublish cp in lcpDennied)
                                    {
                                        ls.AppendValues(cp.IsSelected, cp.ProjectName, cp, cp.ProjectName, false);
                                    }
                                    showAll = true;
                                };
                                popupMenu.Append(miShowDenied);
                            }
                            else
                            {
                                MenuItem miHideDenied = new MenuItem(MainClass.Languages.Translate("hide_denied"));
                                miHideDenied.Activated += delegate(object sender, EventArgs e) {
                                    List <TreeIter> lst = new List <TreeIter>();
                                    ls.Foreach((model, path, iterr) => {
                                        bool cp       = (bool)ls.GetValue(iterr, 4);
                                        bool selected = (bool)ls.GetValue(iterr, 0);
                                        if (!cp && !selected)
                                        {
                                            lst.Add(iterr);
                                        }
                                        return(false);
                                    });

                                    foreach (TreeIter ti2 in lst)
                                    {
                                        TreeIter ti3 = ti2;
                                        ls.Remove(ref ti3);
                                    }

                                    showAll = false;
                                };
                                popupMenu.Append(miHideDenied);
                            }
                            popupMenu.Append(new SeparatorMenuItem());


                            MenuItem miCheckAll = new MenuItem(MainClass.Languages.Translate("check_all"));
                            miCheckAll.Activated += delegate(object sender, EventArgs e) {
                                if ((deviceTyp == (int)DeviceType.Windows) || (deviceTyp == (int)DeviceType.MacOs))
                                {
                                    if (!MainClass.LicencesSystem.CheckFunction("windowsandmac", this))
                                    {
                                        return;
                                    }
                                }

                                int cnt = 0;
                                ls.Foreach((model, path, iterr) => {
                                    CombinePublish cp = (CombinePublish)ls.GetValue(iterr, 2);
                                    cp.IsSelected     = true;
                                    ls.SetValue(iterr, 0, true);
                                    cnt++;
                                    return(false);
                                });
                                nl.SetLabel(String.Format("{0} ({1})", deviceName, cnt));
                            };
                            popupMenu.Append(miCheckAll);

                            MenuItem miUnCheckAll = new MenuItem(MainClass.Languages.Translate("uncheck_all"));
                            miUnCheckAll.Activated += delegate(object sender, EventArgs e) {
                                ls.Foreach((model, path, iterr) => {
                                    CombinePublish cp = (CombinePublish)ls.GetValue(iterr, 2);
                                    cp.IsSelected     = false;
                                    ls.SetValue(iterr, 0, false);
                                    return(false);
                                });
                                nl.SetLabel(String.Format("{0} ({1})", deviceName, 0));
                            };
                            popupMenu.Append(miUnCheckAll);

                            popupMenu.Popup();
                            popupMenu.ShowAll();
                        }
                    }
                };

                tvList.Model = ls;

                if (!validDevice)
                {
                    tvList.Sensitive = false;
                }

                sw.Add(tvList);
                notebook.AppendPage(sw, nl);
            }
        }
コード例 #46
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);

            var c4  = new ComboBoxEntry();
            var la4 = new Label("Selected text: ");

            PackStart(c4);
            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.SelectionChanged += delegate {
                la4.Text = "Selected text: " + c4.TextEntry.SelectedText;
            };
            c4.Completes = true;

            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 + " Length: " + c4.TextEntry.SelectionLength;
            };


            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);
        }
コード例 #47
0
ファイル: DataGrid.cs プロジェクト: pmq20/mono_forked
 public void SetColumnValue(TreeIter iter, int column, string value)
 {
     GLib.Value cell = new GLib.Value(value);
     store.SetValue(iter, column, cell);
 }
コード例 #48
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);
        }
コード例 #49
0
ファイル: MultiplayerView.cs プロジェクト: suicvne/TrueCraft
        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.MainContainer.Remove(this);
                Window.MainContainer.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);
        }
コード例 #50
0
ファイル: MultiplayerView.cs プロジェクト: Zoxive/TrueCraft
        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);
        }