aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.WinForms')
-rw-r--r--ShiftOS.WinForms/DesktopWidgetAttribute.cs5
-rw-r--r--ShiftOS.WinForms/WidgetManager.cs45
-rw-r--r--ShiftOS.WinForms/WinformsDesktop.cs46
3 files changed, 95 insertions, 1 deletions
diff --git a/ShiftOS.WinForms/DesktopWidgetAttribute.cs b/ShiftOS.WinForms/DesktopWidgetAttribute.cs
index 28d50ac..8d3706f 100644
--- a/ShiftOS.WinForms/DesktopWidgetAttribute.cs
+++ b/ShiftOS.WinForms/DesktopWidgetAttribute.cs
@@ -17,5 +17,10 @@ namespace ShiftOS.WinForms
Name = n;
Description = desc;
}
+
+ public override string ToString()
+ {
+ return this.Name + "_" + Description;
+ }
}
}
diff --git a/ShiftOS.WinForms/WidgetManager.cs b/ShiftOS.WinForms/WidgetManager.cs
index 125c804..15e2076 100644
--- a/ShiftOS.WinForms/WidgetManager.cs
+++ b/ShiftOS.WinForms/WidgetManager.cs
@@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
+using Newtonsoft.Json;
using ShiftOS.Engine;
+using ShiftOS.Objects.ShiftFS;
namespace ShiftOS.WinForms
{
@@ -14,7 +17,7 @@ namespace ShiftOS.WinForms
public static Dictionary<DesktopWidgetAttribute, Type> GetAllWidgetTypes()
{
Dictionary<DesktopWidgetAttribute, Type> types = new Dictionary<WinForms.DesktopWidgetAttribute, Type>();
- foreach(var exe in Directory.GetFiles(Environment.CurrentDirectory))
+ foreach(var exe in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
{
if(exe.EndsWith(".exe") || exe.EndsWith(".dll"))
{
@@ -45,6 +48,46 @@ namespace ShiftOS.WinForms
return types;
}
+ internal static void SaveLocation(Type type, Point location)
+ {
+ var dict = new Dictionary<string, Point>();
+ var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute;
+ try
+ {
+ dict = JsonConvert.DeserializeObject<Dictionary<string, Point>>(Utils.ReadAllText(Paths.GetPath("widgets.dat")));
+ dict[attrib.ToString()] = location;
+ }
+ catch
+ {
+ dict.Add(attrib.ToString(), location);
+ }
+ finally
+ {
+ Utils.WriteAllText(Paths.GetPath("widgets.dat"), JsonConvert.SerializeObject(dict));
+ }
+
+ }
+
+ internal static Point LoadLocation(Type type)
+ {
+ var dict = new Dictionary<string, Point>();
+ var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute;
+ try
+ {
+ dict = JsonConvert.DeserializeObject<Dictionary<string, Point>>(Utils.ReadAllText(Paths.GetPath("widgets.dat")));
+
+ return dict[attrib.ToString()];
+
+ }
+ catch
+ {
+ return new Point(-1, -1);
+ }
+ finally
+ {
+ }
+
+ }
}
}
diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs
index 3050cdf..ee0f34d 100644
--- a/ShiftOS.WinForms/WinformsDesktop.cs
+++ b/ShiftOS.WinForms/WinformsDesktop.cs
@@ -452,7 +452,11 @@ namespace ShiftOS.WinForms
foreach(var widget in WidgetManager.GetAllWidgetTypes())
{
UserControl w = (UserControl)Activator.CreateInstance(widget.Value, null);
+
+ w.Location = WidgetManager.LoadLocation(w.GetType());
+
pnlwidgetlayer.Controls.Add(w);
+ MakeWidgetMovable(w);
Widgets.Add(w as IDesktopWidget);
}
}
@@ -481,6 +485,48 @@ namespace ShiftOS.WinForms
PopulatePanelButtons();
}
+ public void MakeWidgetMovable(Control w, Control startCtrl = null)
+ {
+ if (startCtrl == null)
+ startCtrl = w;
+
+ bool moving = false;
+
+ w.MouseDown += (o, a) =>
+ {
+ moving = true;
+ };
+
+ w.MouseMove += (o, a) =>
+ {
+ if (moving == true)
+ {
+ var mPos = Cursor.Position;
+ int mY = mPos.Y - desktoppanel.Height;
+ int mX = mPos.X;
+
+ int ctrlHeight = startCtrl.Height / 2;
+ int ctrlWidth = startCtrl.Width / 2;
+
+ startCtrl.Location = new Point(
+ mX - ctrlWidth,
+ mY - ctrlHeight
+ );
+
+ }
+ };
+
+ w.MouseUp += (o, a) =>
+ {
+ moving = false;
+ WidgetManager.SaveLocation(startCtrl.GetType(), w.Location);
+ };
+
+ foreach (Control c in w.Controls)
+ MakeWidgetMovable(c, startCtrl);
+
+ }
+
public ToolStripMenuItem GetALCategoryWithName(string text)
{
foreach (ToolStripMenuItem menuitem in apps.DropDownItems)