1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine;
using ShiftOS.WinForms.Tools;
using Newtonsoft.Json;
using ShiftOS.Objects.ShiftFS;
namespace ShiftOS.WinForms.Applications
{
[WinOpen("desktop_widgets")]
[Launcher("Widget Manager", true, "al_widget_manager", "Customization")]
[DefaultTitle("Widget Manager")]
[RequiresUpgrade("desktop_widgets")]
public partial class WidgetManagerFrontend : UserControl, IShiftOSWindow
{
public WidgetManagerFrontend()
{
InitializeComponent();
}
Dictionary<string, WidgetDetails> temp_details = null;
public void SetupUI()
{
flbody.Controls.Clear();
if(temp_details == null)
temp_details = new Dictionary<string, WinForms.WidgetDetails>();
foreach(var widgetType in WidgetManager.GetAllWidgetTypes())
{
var details = WidgetManager.LoadDetails(widgetType.Value);
if (temp_details.ContainsKey(widgetType.Key.ToString()))
details = temp_details[widgetType.Key.ToString()];
else
temp_details.Add(widgetType.Key.ToString(), details);
var cbox = new CheckBox();
cbox.Checked = details.IsVisible;
cbox.Size = new Size(32, 32);
cbox.CheckedChanged += (o, a) =>
{
details.IsVisible = cbox.Checked;
};
flbody.Controls.Add(cbox);
cbox.Show();
var title = new Label();
title.Text = widgetType.Key.Name;
title.AutoSize = true;
title.Tag = "header3";
ControlManager.SetupControl(title);
flbody.Controls.Add(title);
title.Show();
var desc = new Label();
desc.Text = widgetType.Key.Description;
flbody.Controls.Add(desc);
flbody.SetFlowBreak(desc, true);
flbody.SetFlowBreak(title, true);
desc.Show();
}
}
public void OnLoad()
{
SetupUI();
}
public void OnSkinLoad()
{
SetupUI();
}
public bool OnUnload()
{
return false;
}
public void OnUpgrade()
{
SetupUI();
}
private void btnapply_Click(object sender, EventArgs e)
{
Utils.WriteAllText(Paths.GetPath("widgets.dat"), JsonConvert.SerializeObject(temp_details));
Desktop.CurrentDesktop.SetupDesktop();
}
private void btnexport_Click(object sender, EventArgs e)
{
FileSkimmerBackend.GetFile(new[] { ".wid" }, FileOpenerStyle.Save, (path) =>
{
Utils.WriteAllText(path, JsonConvert.SerializeObject(temp_details));
});
}
private void btnimport_Click(object sender, EventArgs e)
{
FileSkimmerBackend.GetFile(new[] { ".wid" }, FileOpenerStyle.Open, (path) =>
{
temp_details = JsonConvert.DeserializeObject<Dictionary<string, WidgetDetails>>(Utils.ReadAllText(path));
SetupUI();
});
}
private void btnloaddefault_Click(object sender, EventArgs e)
{
temp_details.Clear();
foreach(var type in WidgetManager.GetAllWidgetTypes())
{
temp_details.Add(type.Key.ToString(), new WidgetDetails
{
IsVisible = false,
Location = new Point(-1, -1)
});
}
SetupUI();
}
private void btnclose_Click(object sender, EventArgs e)
{
AppearanceManager.Close(this);
}
}
}
|