示例#1
0
		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);
		}
		void ShowBatchFixContextMenu (double x, double y, IEnumerable<TreePosition> rows)
		{
			var possibleFixes = rows
				.Select (row => store.GetNavigatorAt (row).GetValue (nodeField))
				.Where (node1 => node1 != null)
				.SelectMany (node2 => node2.AllChildren.Union (new [] { node2 }))
				.Where (node3 => node3.Visible)
				.OfType<IssueSummary> ()
				.Where (issue => issue.Actions.Any (a => a.Batchable))
				.Distinct()
				.GroupBy(issue => issue.InspectorIdString)
				.OrderBy (group => -group.Count ());
				
			var groups = possibleFixes.Take (BatchChoiceCount).ToList ();
			if (!groups.Any ())
				return;

			if (groups.Count == 1) {
				CreateIssueMenu (groups.First ()).Popup (view, x, y);
			} else {
				var menu = new Menu ();
				foreach (var g in groups) {
					var menuItem = new MenuItem (g.First ().ProviderTitle);
					menuItem.SubMenu = CreateIssueMenu (g);
					menu.Items.Add (menuItem);
				}
				menu.Popup (view, x, y);
			}
		}
示例#3
0
        public TreeViews()
        {
            TreeView view = new TreeView();
            TreeStore store = new TreeStore(triState, check, text, desc);
            view.GridLinesVisible = GridLines.Both;

            var triStateCellView = new CheckBoxCellView(triState) { Editable = true, AllowMixed = true };
            triStateCellView.Toggled += (object sender, WidgetEventArgs e) =>
            {
                if (view.CurrentEventRow == null)
                {
                    MessageDialog.ShowError("CurrentEventRow is null. This is not supposed to happen");
                }
                else
                {
                    store.GetNavigatorAt(view.CurrentEventRow).SetValue(text, "TriState Toggled");
                }
            };
            var checkCellView = new CheckBoxCellView(check) { Editable = true };
            checkCellView.Toggled += (object sender, WidgetEventArgs e) =>
            {
                if (view.CurrentEventRow == null)
                {
                    MessageDialog.ShowError("CurrentEventRow is null. This is not supposed to happen");
                }
                else
                {
                    store.GetNavigatorAt(view.CurrentEventRow).SetValue(text, "Toggled");
                }
            };
            view.Columns.Add("TriCheck", triStateCellView);
            view.Columns.Add("Check", checkCellView);
            view.Columns.Add("Item", text);
            view.Columns.Add("Desc", desc);

            store.AddNode().SetValue(text, "One").SetValue(desc, "First").SetValue(triState, CheckBoxState.Mixed);
            store.AddNode().SetValue(text, "Two").SetValue(desc, "Second").AddChild()
                .SetValue(text, "Sub two").SetValue(desc, "Sub second");
            store.AddNode().SetValue(text, "Three").SetValue(desc, "Third").AddChild()
                .SetValue(text, "Sub three").SetValue(desc, "Sub third");
            PackStart(view, true);

            Menu contextMenu = new Menu();
            contextMenu.Items.Add(new MenuItem("Test menu"));
            view.ButtonPressed += delegate(object sender, ButtonEventArgs e)
            {
                TreePosition tmpTreePos;
                RowDropPosition tmpRowDrop;
                if ((e.Button == PointerButton.Right) && view.GetDropTargetRow(e.X, e.Y, out tmpRowDrop, out tmpTreePos))
                {
                    // Set actual row to selected
                    view.SelectRow(tmpTreePos);
                    contextMenu.Popup(view, e.X, e.Y);
                }
            };

            view.DataSource = store;

            Label la = new Label();
            PackStart(la);

            view.SetDragDropTarget(DragDropAction.All, TransferDataType.Text);
            view.SetDragSource(DragDropAction.All, TransferDataType.Text);

            view.DragDrop += delegate(object sender, DragEventArgs e)
            {
                TreePosition node;
                RowDropPosition pos;
                view.GetDropTargetRow(e.Position.X, e.Position.Y, out pos, out node);
                var nav = store.GetNavigatorAt(node);
                la.Text += "Dropped \"" + e.Data.Text + "\" into \"" + nav.GetValue(text) + "\" " + pos + "\n";
                e.Success = true;
            };
            view.DragOver += delegate(object sender, DragOverEventArgs e)
            {
                TreePosition node;
                RowDropPosition pos;
                view.GetDropTargetRow(e.Position.X, e.Position.Y, out pos, out node);
                if (pos == RowDropPosition.Into)
                    e.AllowedAction = DragDropAction.None;
                else
                    e.AllowedAction = e.Action;
            };
            view.DragStarted += delegate(object sender, DragStartedEventArgs e)
            {
                var val = store.GetNavigatorAt(view.SelectedRow).GetValue(text);
                e.DragOperation.Data.AddValue(val);
                e.DragOperation.Finished += delegate(object s, DragFinishedEventArgs args)
                {
                    Console.WriteLine("D:" + args.DeleteSource);
                };
            };
            view.RowExpanding += delegate(object sender, TreeViewRowEventArgs e)
            {
                var val = store.GetNavigatorAt(e.Position).GetValue(text);
                Console.WriteLine("Expanding: " + val);
            };
            view.RowExpanded += delegate(object sender, TreeViewRowEventArgs e)
            {
                var val = store.GetNavigatorAt(e.Position).GetValue(text);
                Console.WriteLine("Expanded: " + val);
            };
            view.RowCollapsing += delegate(object sender, TreeViewRowEventArgs e)
            {
                var val = store.GetNavigatorAt(e.Position).GetValue(text);
                Console.WriteLine("Collapsing: " + val);
            };
            view.RowCollapsed += delegate(object sender, TreeViewRowEventArgs e)
            {
                var val = store.GetNavigatorAt(e.Position).GetValue(text);
                Console.WriteLine("Collapsed: " + val);
            };

            int addCounter = 0;
            view.KeyPressed += (sender, e) =>
            {
                if (e.Key == Key.Insert)
                {
                    TreeNavigator n;
                    if (view.SelectedRow != null)
                        n = store.InsertNodeAfter(view.SelectedRow).SetValue(text, "Inserted").SetValue(desc, "Desc");
                    else
                        n = store.AddNode().SetValue(text, "Inserted").SetValue(desc, "Desc");
                    view.ExpandToRow(n.CurrentPosition);
                    view.ScrollToRow(n.CurrentPosition);
                    view.UnselectAll();
                    view.SelectRow(n.CurrentPosition);
                    view.FocusedRow = n.CurrentPosition;
                }
            };
            Button addButton = new Button("Add");
            addButton.Clicked += delegate(object sender, EventArgs e)
            {
                addCounter++;
                TreeNavigator n;
                if (view.SelectedRow != null)
                    n = store.AddNode(view.SelectedRow).SetValue(text, "Added " + addCounter).SetValue(desc, "Desc");
                else
                    n = store.AddNode().SetValue(text, "Added " + addCounter).SetValue(desc, "Desc");
                view.ExpandToRow(n.CurrentPosition);
                view.ScrollToRow(n.CurrentPosition);
                view.SelectRow(n.CurrentPosition);
            };
            PackStart(addButton);

            Button removeButton = new Button("Remove Selection");
            removeButton.Clicked += delegate(object sender, EventArgs e)
            {
                foreach (TreePosition row in view.SelectedRows)
                {
                    store.GetNavigatorAt(row).Remove();
                }
            };
            PackStart(removeButton);

            var label = new Label();
            PackStart(label);

            view.RowExpanded += (sender, e) => label.Text = "Row expanded: " + store.GetNavigatorAt(e.Position).GetValue(text);
        }
示例#4
0
文件: LogViewer.cs 项目: rte-se/emul8
        private void Init()
        {
            progressWidget = new ProgressWidget();

            refreshButton = new Button("Refresh");
            refreshButton.Clicked += async (sender, e) => await RebuildIndex();

            pageStatusLabel = new Label();

            lastRefreshLabel = new Label("-");
            var autoRefreshBox = new HBox();
            autoRefreshBox.PackStart(pageStatusLabel);
            autoRefreshBox.PackStart(new Label(string.Empty), true);
            autoRefreshBox.PackStart(progressWidget);
            autoRefreshBox.PackStart(new Label(string.Empty), true);
            autoRefreshBox.PackStart(new Label("Log state from:"));
            autoRefreshBox.PackStart(lastRefreshLabel);
            autoRefreshBox.PackStart(refreshButton);
            PackStart(autoRefreshBox);

            var hbox = new HBox();

            var buttons = new LogLevelsSelectionWidget();

            hbox.PackStart(new Label("Filter:"));
            hbox.PackStart(buttons);

            hbox.PackStart(new HSeparator());
            filterTextEntry = new TextEntry();
            hbox.PackStart(filterTextEntry, true);
            filterTextEntry.KeyReleased += async (sender, e) => 
            {
                if (e.Key == Key.Return || e.Key == Key.NumPadEnter)
                {
                    await HandleFilterButtonClicked();
                }
            };
            var queryButton = new Button("Query");
            queryButton.Clicked += async (sender, e) => await HandleFilterButtonClicked();

            hbox.PackStart(queryButton);

            var helpButton = new Button("Help");
            helpButton.Clicked += (sender, e) => 
            {
                using (var dialog = new LogViewerHelpDialog())
                {
                    dialog.Run();
                }
            };
            hbox.PackStart(helpButton);

            listViewLog = new ListViewLog(false);
            listViewLog.ButtonPressed += (s, ea) =>
            {
                if (ea.Button != PointerButton.Right)
                {
                    return;
                }

                var menu = new Menu();
                var item = new MenuItem("Show surrounding log entries");

                item.Clicked += async (sender, e) =>
                {
                    var id = listViewLog.SelectedItemId;
                    if (!id.HasValue)
                    {
                        return;
                    }

                    var idFrom = Math.Max(0, id.Value - 20);
                    var idTo = id.Value + 20;
                    filterTextEntry.Text = string.Format("id:[{0} TO {1}]", idFrom, idTo);
                    await FilterEntriesAsync(progressWidget.ProgressMonitor);
                };

                menu.Items.Add(item);
                menu.Popup();
            };

            PackStart(listViewLog, true);
            PackStart(hbox);

            buttons.SelectionChanged += async (level, isSelected) => 
            {
                if (isSelected)
                {
                    levels.Add(level);
                }
                else
                {
                    levels.Remove(level);
                }
                await FilterEntriesAsync(progressWidget.ProgressMonitor, true);
            };

            listViewLog.Scrolled += async state =>
            {
                if(Interlocked.Increment(ref eventDepth) > 1)
                {
                    Interlocked.Decrement(ref eventDepth);
                    return;
                }

                await LoadEntriesAsync(progressWidget.ProgressMonitor, 
                    state == ListViewLog.ScrolledState.ScrolledUp ? Direction.Backward : Direction.Forward,
                    () => Interlocked.Decrement(ref eventDepth));
            };

            var searchBox = new HBox();
            searchTextEntry = new TextEntry();
            searchTextEntry.KeyReleased += async (sender, e) => 
            {
                if (e.Key == Key.Return || e.Key == Key.NumPadEnter)
                {
                    await HandleSearchButtonClicked();
                }
            };
            searchBox.PackStart(new Label("Search:"));
            searchBox.PackStart(searchTextEntry, true);
            searchButton = new Button("Search");
            searchButton.Clicked += async (sender, e) => await HandleSearchButtonClicked();
            searchBox.PackStart(searchButton);
            searchLabel = new Label();
            nextSearchResultButton = new Button("Next");
            prevSearchResultButton = new Button("Previous");
            resetSearchButton = new Button("Reset");
            resetSearchButton.Clicked += (sender, e) => ResetSearch();
            nextSearchResultButton.Clicked += async (sender, e) => await SearchEntriesAsync(progressWidget.ProgressMonitor, Direction.Forward);
            prevSearchResultButton.Clicked += async (sender, e) => await SearchEntriesAsync(progressWidget.ProgressMonitor, Direction.Backward);
            searchBox.PackStart(searchLabel);
            searchBox.PackStart(nextSearchResultButton);
            searchBox.PackStart(prevSearchResultButton);
            searchBox.PackStart(resetSearchButton);

            PackStart(searchBox);
            ResetSearch();

            RefreshPaging(0);
        }