From 178b18aaeb1fa1508d5ad60d7e9b249017efff9d Mon Sep 17 00:00:00 2001 From: Pedro Larouca Date: Wed, 21 Mar 2018 02:25:53 +0000 Subject: [PATCH 1/4] [Samples] Fix the completion entry code, Matchfunc was not correctly used. Added insensitive entry sample. --- .../Samples/Sections/Widgets/EntrySection.cs | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/Source/Samples/Sections/Widgets/EntrySection.cs b/Source/Samples/Sections/Widgets/EntrySection.cs index e9adcd39f..dbdcc7943 100644 --- a/Source/Samples/Sections/Widgets/EntrySection.cs +++ b/Source/Samples/Sections/Widgets/EntrySection.cs @@ -18,6 +18,7 @@ namespace Samples AddItem(CreateCustomActionsEntry()); AddItem(CreateProgressEntry()); AddItem(CreateCompletionEntry()); + AddItem(CreateInsensitiveEntry()); } public (string, Widget) CreateSimpleEntry() @@ -123,44 +124,41 @@ namespace Samples store.AppendValues("Better and bigger example"); store.AppendValues("Some other example"); - // create tree column - var column = new TreeViewColumn(); - column.Reorderable = false; - column.SortIndicator = false; - column.Clickable = true; - column.SortColumnId = 0; - - // create cells - var cell = new CellRendererText(); - column.PackStart(cell, true); - - // set cell functions - column.SetCellDataFunc(cell, (TreeViewColumn tree_column, CellRenderer cellRenderer, ITreeModel tree_model, TreeIter iter) => - { - var m = tree_model.GetValue(iter, 0); - (cellRenderer as CellRendererText).Text = (string)m; - }); - - // model filter - var filter = new TreeModelFilter(store, null); - filter.VisibleFunc = (model, iter) => - { - if (string.IsNullOrEmpty(entry.Text)) - return true; - - var o = model.GetValue(iter, 0); - var searchString = o as string; - if (!string.IsNullOrEmpty(searchString)) - return searchString.StartsWith(entry.Text, System.StringComparison.InvariantCultureIgnoreCase); - - return true; - }; - // assign treemodel as the completion - completion.Model = filter; + completion.Model = store; + + // lets override the default match function so we can use the contains mode + // instead of the default startswith + completion.MatchFunc = EntryCompletionMatchFunc; completion.TextColumn = 0; + return ("Completion Entry:",entry); } + + private bool EntryCompletionMatchFunc(EntryCompletion completion, string key, TreeIter iter) + { + if (string.IsNullOrEmpty(key)) + return false; + + var o = completion.Model.GetValue(iter, 0); + var stringToSearch = o as string; + + if (!string.IsNullOrEmpty(stringToSearch)) + return stringToSearch.IndexOf(key, System.StringComparison.InvariantCultureIgnoreCase) >= 0; + + return false; + } + + public (string, Widget) CreateInsensitiveEntry() + { + var entry = new Entry(); + entry.Text = "Cannot change this"; + + entry.Sensitive = false; + + return ("Insensitive entry:", entry); + } + } } From 93661405447f29d97f5641db7a3fb00766ba7e41 Mon Sep 17 00:00:00 2001 From: Pedro Larouca Date: Wed, 21 Mar 2018 02:26:32 +0000 Subject: [PATCH 2/4] [Samples] fix pulse progressbar comment on code --- Source/Samples/Sections/Widgets/ProgressBarSection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Samples/Sections/Widgets/ProgressBarSection.cs b/Source/Samples/Sections/Widgets/ProgressBarSection.cs index 26933fc8a..0d86e5b24 100644 --- a/Source/Samples/Sections/Widgets/ProgressBarSection.cs +++ b/Source/Samples/Sections/Widgets/ProgressBarSection.cs @@ -68,7 +68,7 @@ namespace Samples public (string, Widget) CreatePulseProgressBar() { - // this is used when application can report progress + // this is used when application cant report progress var pb = new ProgressBar(); From ed53817b9902adcfda6ac01c90c160f4e92ac64a Mon Sep 17 00:00:00 2001 From: Pedro Larouca Date: Wed, 21 Mar 2018 02:27:44 +0000 Subject: [PATCH 3/4] [Samples] ComboBox samples, still missing some major combo features. --- Source/Samples/Samples.csproj | 47 +++++++++ .../Sections/Widgets/ComboBoxSection.cs | 97 +++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 Source/Samples/Sections/Widgets/ComboBoxSection.cs diff --git a/Source/Samples/Samples.csproj b/Source/Samples/Samples.csproj index 6d8640523..79e9f4006 100644 --- a/Source/Samples/Samples.csproj +++ b/Source/Samples/Samples.csproj @@ -25,4 +25,51 @@ + + + GtkSharp.Samples.Category.cs + + + GtkSharp.Samples.ListSection.cs + + + GtkSharp.Samples.SectionAttribute.cs + + + GtkSharp.Samples.AboutDialogSection.cs + + + GtkSharp.Samples.ButtonSection.cs + + + GtkSharp.Samples.ColorButtonSection.cs + + + GtkSharp.Samples.EntrySection.cs + + + GtkSharp.Samples.LabelSection.cs + + + GtkSharp.Samples.LevelBarSection.cs + + + GtkSharp.Samples.LinkButtonSection.cs + + + GtkSharp.Samples.ProgressBarSection.cs + + + GtkSharp.Samples.SpinButtonSection.cs + + + GtkSharp.Samples.SpinnerSection.cs + + + GtkSharp.Samples.SwitchSection.cs + + + GtkSharp.Samples.ToggleButtonSection.cs + + diff --git a/Source/Samples/Sections/Widgets/ComboBoxSection.cs b/Source/Samples/Sections/Widgets/ComboBoxSection.cs new file mode 100644 index 000000000..0f8d0d4cc --- /dev/null +++ b/Source/Samples/Sections/Widgets/ComboBoxSection.cs @@ -0,0 +1,97 @@ +// This is free and unencumbered software released into the public domain. +// Happy coding!!! - GtkSharp Team + +using Gtk; + +namespace Samples +{ + [Section(ContentType = typeof(ComboBox), Category = Category.Widgets)] + class ComboBoxSection : ListSection + { + public ComboBoxSection() + { + AddItem(CreateSimpleComboBox()); + AddItem(CreateMultiColumnComboBox()); + AddItem(CreateEditableComboBox()); + } + + public (string, Widget) CreateSimpleComboBox() + { + // initialize with a simple string list + var combo = new ComboBox( + new string[] + { + "Combo Entry 1", + "Combo Entry 2", + "Combo Entry 3", + "Combo Entry 4" + } + ); + + // event to notify for index changes in our combo + combo.Changed += (sender, e) => + ApplicationOutput.WriteLine(sender, $"Index changed to:{((ComboBox)sender).Active}"); + + // set the active selection to index 2 (Combo Entry 3) + combo.Active = 2; + + return ("Simple combo:", combo); + } + + public (string, Widget) CreateMultiColumnComboBox() + { + // create a store for our combo + var store = new ListStore(typeof(string), typeof(string), typeof(bool)); + + // lets append some stock icons, passing the icon names, and a simple text column + store.AppendValues("dialog-warning", "Warning", true); + store.AppendValues("process-stop", "Stop", false); + store.AppendValues("document-new", "New", true); + store.AppendValues("edit-clear", "Clear", true); + + // create cells + var imageCell = new CellRendererPixbuf(); + var textCell = new CellRendererText(); + + // create the combo and pass the values in + var combo = new ComboBox(store); + combo.PackStart(imageCell, true); + combo.PackStart(textCell, true); + + // add combo attributes to show in columns + combo.AddAttribute(imageCell, "icon-name", 0); + combo.AddAttribute(textCell, "text", 1); + + // lets use the store bool values to control sensitive rows + // Process-stop (store index one) should be disabled in this sample + // For a ComboBox item to be disabled, all cell renderers for the item need to have + // their sensitivity disabled + combo.AddAttribute(imageCell, "sensitive", 2); + combo.AddAttribute(textCell, "sensitive", 2); + + // listen to index changed on combo + combo.Changed += (sender, e) => + ApplicationOutput.WriteLine(sender, $"Index changed to:{((ComboBox)sender).Active}"); + + // lets preselect the first option + combo.Active = 0; + + return ("Combo with Icons and Text:", combo); + } + + public (string, Widget) CreateEditableComboBox() + { + var combo = ComboBoxText.NewWithEntry(); + combo.AppendText("Example 1"); + combo.AppendText("Example 2"); + combo.AppendText("Example 3"); + combo.AppendText("Example 4"); + + // combos with entry have a real entry inside it + // we can use it by + combo.Entry.PlaceholderText = "Write something"; + + return ("Combo with entry:", combo); + } + } +} From ff82c2ab4aaa4cb1bc7102cfad54d1046f6f76d6 Mon Sep 17 00:00:00 2001 From: Pedro Larouca Date: Wed, 21 Mar 2018 22:50:28 +0000 Subject: [PATCH 4/4] [Samples] applied fix proposal --- Source/Samples/Samples.csproj | 47 ------------------- .../Samples/Sections/Widgets/EntrySection.cs | 29 ++++++------ .../Sections/Widgets/ProgressBarSection.cs | 2 +- 3 files changed, 15 insertions(+), 63 deletions(-) diff --git a/Source/Samples/Samples.csproj b/Source/Samples/Samples.csproj index 79e9f4006..6d8640523 100644 --- a/Source/Samples/Samples.csproj +++ b/Source/Samples/Samples.csproj @@ -25,51 +25,4 @@ - - - GtkSharp.Samples.Category.cs - - - GtkSharp.Samples.ListSection.cs - - - GtkSharp.Samples.SectionAttribute.cs - - - GtkSharp.Samples.AboutDialogSection.cs - - - GtkSharp.Samples.ButtonSection.cs - - - GtkSharp.Samples.ColorButtonSection.cs - - - GtkSharp.Samples.EntrySection.cs - - - GtkSharp.Samples.LabelSection.cs - - - GtkSharp.Samples.LevelBarSection.cs - - - GtkSharp.Samples.LinkButtonSection.cs - - - GtkSharp.Samples.ProgressBarSection.cs - - - GtkSharp.Samples.SpinButtonSection.cs - - - GtkSharp.Samples.SpinnerSection.cs - - - GtkSharp.Samples.SwitchSection.cs - - - GtkSharp.Samples.ToggleButtonSection.cs - - diff --git a/Source/Samples/Sections/Widgets/EntrySection.cs b/Source/Samples/Sections/Widgets/EntrySection.cs index dbdcc7943..424f27b68 100644 --- a/Source/Samples/Sections/Widgets/EntrySection.cs +++ b/Source/Samples/Sections/Widgets/EntrySection.cs @@ -129,27 +129,26 @@ namespace Samples // lets override the default match function so we can use the contains mode // instead of the default startswith - completion.MatchFunc = EntryCompletionMatchFunc; + completion.MatchFunc = (EntryCompletion comp, string key, TreeIter iter) => + { + if (string.IsNullOrEmpty(key)) + return false; + + var o = comp.Model.GetValue(iter, 0); + var stringToSearch = o as string; + + if (!string.IsNullOrEmpty(stringToSearch)) + return stringToSearch.IndexOf(key, System.StringComparison.InvariantCultureIgnoreCase) >= 0; + + return false; + }; + completion.TextColumn = 0; return ("Completion Entry:",entry); } - private bool EntryCompletionMatchFunc(EntryCompletion completion, string key, TreeIter iter) - { - if (string.IsNullOrEmpty(key)) - return false; - - var o = completion.Model.GetValue(iter, 0); - var stringToSearch = o as string; - - if (!string.IsNullOrEmpty(stringToSearch)) - return stringToSearch.IndexOf(key, System.StringComparison.InvariantCultureIgnoreCase) >= 0; - - return false; - } - public (string, Widget) CreateInsensitiveEntry() { var entry = new Entry(); diff --git a/Source/Samples/Sections/Widgets/ProgressBarSection.cs b/Source/Samples/Sections/Widgets/ProgressBarSection.cs index 0d86e5b24..0508f38f4 100644 --- a/Source/Samples/Sections/Widgets/ProgressBarSection.cs +++ b/Source/Samples/Sections/Widgets/ProgressBarSection.cs @@ -68,7 +68,7 @@ namespace Samples public (string, Widget) CreatePulseProgressBar() { - // this is used when application cant report progress + // this is used when application can't report progress var pb = new ProgressBar();