implemented settings window!! 0u0
This commit is contained in:
parent
ec43694b7c
commit
3acd72f575
5 changed files with 155 additions and 21 deletions
|
@ -513,7 +513,7 @@ namespace Buypeeb {
|
|||
sorted = values.OrderBy(item => item.endDate);
|
||||
}
|
||||
|
||||
if (settings.displayFavouritesAtTopOfList) {
|
||||
if (settings.showFavouritesAtTopOfList) {
|
||||
foreach (var item in sorted.Where(item => item.favourite)) {
|
||||
items.AppendValues(item);
|
||||
}
|
||||
|
@ -737,6 +737,13 @@ namespace Buypeeb {
|
|||
}
|
||||
}
|
||||
|
||||
private void ButtonSettingsClicked(object sender, EventArgs args) {
|
||||
var win = new SettingsWindow(this.settings);
|
||||
Application.AddWindow(win);
|
||||
win.DeleteEvent += this.WindowSettingsClosed;
|
||||
win.Show();
|
||||
}
|
||||
|
||||
private void TreeViewItemsSelectionChanged(object sender, EventArgs a) {
|
||||
this.UpdateSelectionView();
|
||||
}
|
||||
|
@ -784,7 +791,7 @@ namespace Buypeeb {
|
|||
ToggleButton s = (ToggleButton)sender;
|
||||
this.selectedItem.favourite = s.Active;
|
||||
|
||||
if (this.settings.displayFavouritesAtTopOfList) {
|
||||
if (this.settings.showFavouritesAtTopOfList) {
|
||||
var id = this.selectedItem.id;
|
||||
this.RenderList();
|
||||
}
|
||||
|
@ -795,7 +802,6 @@ namespace Buypeeb {
|
|||
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonSelectedNotesClearClicked(object sender, EventArgs args) {
|
||||
|
@ -822,6 +828,10 @@ namespace Buypeeb {
|
|||
this.RenderList();
|
||||
}
|
||||
|
||||
private void WindowSettingsClosed(object sender, EventArgs args) {
|
||||
this.RenderList();
|
||||
}
|
||||
|
||||
// timers
|
||||
|
||||
/// <summary>
|
||||
|
@ -920,7 +930,7 @@ namespace Buypeeb {
|
|||
ending += end.ToString("MMM d ");
|
||||
}
|
||||
ending += end.ToString("HH:mm");
|
||||
if (this.settings.displaySecondsInList) {
|
||||
if (this.settings.showSecondsInListView) {
|
||||
// add the seconds on to the end
|
||||
ending += end.ToString(":ss");
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@ namespace Buypeeb {
|
|||
public int favouriteUpdateInterval { get; set; } = 5 * 60;
|
||||
public int updateIntervalCritical { get; set; } = 60;
|
||||
public int favouriteUpdateIntervalCritical { get; set; } = 30;
|
||||
public bool displaySecondsInList { get; set; } = true;
|
||||
public bool displayFavouritesAtTopOfList { get; set; } = true;
|
||||
public bool showSecondsInListView { get; set; } = true;
|
||||
public bool autosave { get; set; } = true;
|
||||
public bool showFavouritesAtTopOfList { get; set; } = true;
|
||||
|
||||
public Dictionary<string, YahooAuctionsItem> watchlist {
|
||||
get; set;
|
||||
|
|
87
SettingsWindow.cs
Normal file
87
SettingsWindow.cs
Normal file
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Gtk;
|
||||
|
||||
namespace Buypeeb {
|
||||
class SettingsWindow : Window {
|
||||
private List<Switch> generalSwitches = new List<Switch>();
|
||||
private List<Entry> updateIntervalEntries = new List<Entry>();
|
||||
private Settings settings;
|
||||
private Builder builder;
|
||||
|
||||
private List<String> generalSwitchNames = new List<String> { "ShowSecondsInListView", "Autosave", "ShowFavouritesAtTopOfList" };
|
||||
private List<String> updateIntervalEntryNames = new List<String> { "UpdateInterval", "UpdateIntervalCritical", "FavouriteUpdateInterval", "FavouriteUpdateIntervalCritical" };
|
||||
|
||||
public SettingsWindow(Settings settings) : this(new Builder("settings.glade"), settings) { }
|
||||
|
||||
private SettingsWindow(Builder builder, Settings settings) : base(builder.GetObject("WindowSettings").Handle) {
|
||||
this.Title = "Buypeeb - Settings";
|
||||
this.settings = settings;
|
||||
this.builder = builder;
|
||||
builder.Autoconnect(this);
|
||||
|
||||
foreach (var name in this.generalSwitchNames) {
|
||||
var s = (Switch)builder.GetObject($"Switch{name}");
|
||||
this.generalSwitches.Add(s);
|
||||
s.Active = GetSetting<bool>(this.PropertyName(name));
|
||||
}
|
||||
|
||||
foreach (var name in this.updateIntervalEntryNames) {
|
||||
var e = (Entry)builder.GetObject($"Entry{name}");
|
||||
this.updateIntervalEntries.Add(e);
|
||||
e.Text = GetSetting<int>(this.PropertyName(name)).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private T GetSetting<T>(string property) {
|
||||
return (T)this.settings.GetType().GetProperty(property).GetValue(this.settings, null);
|
||||
}
|
||||
|
||||
private void SetSetting<T>(string property, T value) {
|
||||
this.settings.GetType().GetProperty(property).SetValue(this.settings, value);
|
||||
}
|
||||
|
||||
private string PropertyName(string property) {
|
||||
// replace "PropertyName" with "propertyName";
|
||||
return property[0].ToString().ToLower() + property.Substring(1);
|
||||
}
|
||||
|
||||
private void ButtonSaveClicked(object sender, EventArgs args) {
|
||||
// first, validate all the intervals
|
||||
bool failed = false;
|
||||
foreach (var name in this.updateIntervalEntryNames) {
|
||||
var e = (Entry)builder.GetObject($"Entry{name}");
|
||||
if (!int.TryParse(e.Text, out int result)) {
|
||||
failed = true;
|
||||
}
|
||||
else {
|
||||
if (result < 30 || result > 6000) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed) {
|
||||
var md = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Update intervals must be a whole number between 30 and 6000.");
|
||||
md.Run();
|
||||
md.Dispose();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// validation success!
|
||||
|
||||
foreach (var name in this.updateIntervalEntryNames) {
|
||||
this.SetSetting<int>(PropertyName(name), int.Parse((builder.GetObject($"Entry{name}") as Entry).Text));
|
||||
}
|
||||
|
||||
foreach (var name in this.generalSwitchNames) {
|
||||
this.SetSetting<bool>(PropertyName(name), (builder.GetObject($"Switch{name}") as Switch).Active);
|
||||
}
|
||||
this.Dispose();
|
||||
}
|
||||
|
||||
private void ButtonCancelClicked(object sender, EventArgs args) {
|
||||
this.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.36.0 -->
|
||||
<!-- Generated with glade 3.22.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.22"/>
|
||||
<object class="GtkImage" id="ImageFilter">
|
||||
|
@ -253,6 +253,9 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="default_width">810</property>
|
||||
<property name="default_height">500</property>
|
||||
<child type="titlebar">
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
|
@ -447,12 +450,12 @@
|
|||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="sensitive">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Settings</property>
|
||||
<property name="label" translatable="yes">Settings</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-preferences</property>
|
||||
<signal name="clicked" handler="ButtonSettingsClicked" swapped="no"/>
|
||||
<accelerator key="comma" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -1140,8 +1143,5 @@
|
|||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
<!-- Generated with glade 3.22.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkWindow">
|
||||
<object class="GtkWindow" id="WindowSettings">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="default_width">440</property>
|
||||
<child type="titlebar">
|
||||
<placeholder/>
|
||||
|
@ -29,6 +30,8 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="row_spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
|
@ -44,7 +47,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch">
|
||||
<object class="GtkSwitch" id="SwitchShowSecondsInListView">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
|
@ -68,7 +71,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch">
|
||||
<object class="GtkSwitch" id="SwitchAutosave">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
|
@ -78,6 +81,30 @@
|
|||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label" translatable="yes">Show favourites at top of list</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="SwitchShowFavouritesAtTopOfList">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="tab">
|
||||
|
@ -95,7 +122,10 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">20</property>
|
||||
<property name="column_spacing">3</property>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
|
@ -194,13 +224,14 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry">
|
||||
<object class="GtkEntry" id="EntryUpdateInterval">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">2</property>
|
||||
<property name="margin_bottom">2</property>
|
||||
<property name="max_length">3</property>
|
||||
<property name="width_chars">5</property>
|
||||
<property name="input_purpose">number</property>
|
||||
</object>
|
||||
|
@ -210,13 +241,14 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry">
|
||||
<object class="GtkEntry" id="EntryUpdateIntervalCritical">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">2</property>
|
||||
<property name="margin_bottom">2</property>
|
||||
<property name="max_length">3</property>
|
||||
<property name="width_chars">5</property>
|
||||
<property name="input_purpose">number</property>
|
||||
</object>
|
||||
|
@ -226,13 +258,14 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry">
|
||||
<object class="GtkEntry" id="EntryFavouriteUpdateInterval">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">2</property>
|
||||
<property name="margin_bottom">2</property>
|
||||
<property name="max_length">3</property>
|
||||
<property name="width_chars">5</property>
|
||||
<property name="input_purpose">number</property>
|
||||
</object>
|
||||
|
@ -242,13 +275,14 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry">
|
||||
<object class="GtkEntry" id="EntryFavouriteUpdateIntervalCritical">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">2</property>
|
||||
<property name="margin_bottom">2</property>
|
||||
<property name="max_length">3</property>
|
||||
<property name="width_chars">5</property>
|
||||
<property name="input_purpose">number</property>
|
||||
</object>
|
||||
|
@ -287,7 +321,7 @@
|
|||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">About</property>
|
||||
<property name="label" translatable="yes">About Buypeeb</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
|
@ -300,10 +334,11 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Cancel</property>
|
||||
<property name="label" translatable="yes">Save</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="ButtonSaveClicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -314,10 +349,11 @@
|
|||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">Save</property>
|
||||
<property name="label" translatable="yes">Cancel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="ButtonCancelClicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
|
Loading…
Reference in a new issue