implement save as and open buttons
This commit is contained in:
parent
4544acd01e
commit
9913c3118f
2 changed files with 68 additions and 7 deletions
|
@ -305,12 +305,12 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessageDialog OkCancelDialogue(string message) {
|
private MessageDialog MsgBox(string message, ButtonsType buttonsType = ButtonsType.OkCancel) {
|
||||||
var md = new MessageDialog(
|
var md = new MessageDialog(
|
||||||
parent_window: this,
|
parent_window: this,
|
||||||
flags: DialogFlags.DestroyWithParent | DialogFlags.Modal,
|
flags: DialogFlags.DestroyWithParent | DialogFlags.Modal,
|
||||||
type: MessageType.Question,
|
type: MessageType.Question,
|
||||||
bt: ButtonsType.OkCancel,
|
bt: buttonsType,
|
||||||
format: message
|
format: message
|
||||||
);
|
);
|
||||||
md.KeepAbove = true;
|
md.KeepAbove = true;
|
||||||
|
@ -393,7 +393,7 @@ namespace Buypeeb {
|
||||||
|
|
||||||
private void ButtonClearEndedClicked(object sender, EventArgs a) {
|
private void ButtonClearEndedClicked(object sender, EventArgs a) {
|
||||||
Console.WriteLine("ButtonClearEndedClicked");
|
Console.WriteLine("ButtonClearEndedClicked");
|
||||||
var md = this.OkCancelDialogue("Are you sure you want to remove all ended auctions from the list?");
|
var md = this.MsgBox("Are you sure you want to remove all ended auctions from the list?");
|
||||||
var r = (ResponseType)md.Run();
|
var r = (ResponseType)md.Run();
|
||||||
md.Dispose();
|
md.Dispose();
|
||||||
if (r != ResponseType.Ok) {
|
if (r != ResponseType.Ok) {
|
||||||
|
@ -418,12 +418,73 @@ namespace Buypeeb {
|
||||||
Console.WriteLine("ButtonClearAllClicked");
|
Console.WriteLine("ButtonClearAllClicked");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonOpenClicked(object sender, EventArgs a) {
|
||||||
|
var od = new FileChooserDialog(
|
||||||
|
title: "Open userdata.json",
|
||||||
|
parent: this,
|
||||||
|
action: FileChooserAction.Open,
|
||||||
|
"Cancel", ResponseType.Cancel, "Open", ResponseType.Accept
|
||||||
|
);
|
||||||
|
|
||||||
|
var odf = new FileFilter();
|
||||||
|
odf.Name = "JSON files";
|
||||||
|
odf.AddMimeType("application/json");
|
||||||
|
odf.AddPattern("*.json");
|
||||||
|
od.AddFilter(odf);
|
||||||
|
|
||||||
|
if (od.Run() == (int)ResponseType.Accept) {
|
||||||
|
try {
|
||||||
|
string j = File.ReadAllText(od.Filename);
|
||||||
|
this.settings = JsonSerializer.Deserialize<Settings>(j);
|
||||||
|
this.RenderList();
|
||||||
|
this.UpdateItems();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Console.WriteLine(e);
|
||||||
|
MsgBox($"Failed to load {od.Filename}!\n{e.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
od.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonSaveClicked(object sender, EventArgs a) {
|
private void ButtonSaveClicked(object sender, EventArgs a) {
|
||||||
this.SaveSettings();
|
this.SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSaveAsClicked(object sender, EventArgs a) {
|
||||||
|
var sd = new FileChooserDialog(
|
||||||
|
title: "Save userdata.json",
|
||||||
|
parent: this,
|
||||||
|
action: FileChooserAction.Save,
|
||||||
|
"Cancel", ResponseType.Cancel, "Save", ResponseType.Accept
|
||||||
|
);
|
||||||
|
sd.CurrentName = "userdata.json";
|
||||||
|
|
||||||
|
var sdf = new FileFilter();
|
||||||
|
sdf.Name = "JSON files";
|
||||||
|
sdf.AddMimeType("application/json");
|
||||||
|
sdf.AddPattern("*.json");
|
||||||
|
sd.AddFilter(sdf);
|
||||||
|
|
||||||
|
if (sd.Run() == (int)ResponseType.Accept) {
|
||||||
|
try {
|
||||||
|
if (!File.Exists(sd.Filename)) {
|
||||||
|
var fs = File.CreateText(sd.Filename);
|
||||||
|
fs.Close();
|
||||||
|
}
|
||||||
|
File.WriteAllText(sd.Filename, JsonSerializer.Serialize(this.settings));
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Console.WriteLine(e);
|
||||||
|
MsgBox($"Failed to write {sd.Filename}!\n{e.Message}.", ButtonsType.Ok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sd.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonQuitClicked(object sender, EventArgs a) {
|
private void ButtonQuitClicked(object sender, EventArgs a) {
|
||||||
var md = this.OkCancelDialogue("Are you sure you want to quit?");
|
var md = this.MsgBox("Are you sure you want to quit?");
|
||||||
|
|
||||||
ResponseType response = (ResponseType)md.Run();
|
ResponseType response = (ResponseType)md.Run();
|
||||||
md.Dispose();
|
md.Dispose();
|
||||||
|
@ -448,7 +509,7 @@ namespace Buypeeb {
|
||||||
private void ButtonSelectedRemoveClicked(object sender, EventArgs a) {
|
private void ButtonSelectedRemoveClicked(object sender, EventArgs a) {
|
||||||
var item = this.selectedItem;
|
var item = this.selectedItem;
|
||||||
|
|
||||||
var md = this.OkCancelDialogue($"Are you sure you want to remove the item \"{item.name}\"?"); // TODO: this looks bad being all on one line
|
var md = this.MsgBox($"Are you sure you want to remove the item \"{item.name}\"?"); // TODO: this looks bad being all on one line
|
||||||
|
|
||||||
ResponseType response = (ResponseType)md.Run();
|
ResponseType response = (ResponseType)md.Run();
|
||||||
md.Dispose();
|
md.Dispose();
|
||||||
|
|
|
@ -152,12 +152,12 @@
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToolButton">
|
<object class="GtkToolButton">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="sensitive">False</property>
|
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="tooltip_text" translatable="yes">Open</property>
|
<property name="tooltip_text" translatable="yes">Open</property>
|
||||||
<property name="label" translatable="yes">Open</property>
|
<property name="label" translatable="yes">Open</property>
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
<property name="stock_id">gtk-open</property>
|
<property name="stock_id">gtk-open</property>
|
||||||
|
<signal name="clicked" handler="ButtonOpenClicked" swapped="no"/>
|
||||||
<accelerator key="o" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
<accelerator key="o" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
@ -184,12 +184,12 @@
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToolButton">
|
<object class="GtkToolButton">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="sensitive">False</property>
|
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="tooltip_text" translatable="yes">Export as...</property>
|
<property name="tooltip_text" translatable="yes">Export as...</property>
|
||||||
<property name="label" translatable="yes">Export as...</property>
|
<property name="label" translatable="yes">Export as...</property>
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
<property name="stock_id">gtk-save-as</property>
|
<property name="stock_id">gtk-save-as</property>
|
||||||
|
<signal name="clicked" handler="ButtonSaveAsClicked" swapped="no"/>
|
||||||
<accelerator key="e" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
<accelerator key="e" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
|
Loading…
Reference in a new issue