aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs
diff options
context:
space:
mode:
Diffstat (limited to 'source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs')
-rw-r--r--source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs459
1 files changed, 226 insertions, 233 deletions
diff --git a/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs b/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs
index 36ae34b..83b71fd 100644
--- a/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs
+++ b/source/WindowsFormsApplication1/Desktop/ShiftOSDesktop.cs
@@ -6,7 +6,7 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
-using System.Windows.Forms;
+using ShiftUI;
using SaveSystem;
using System.Threading;
using Newtonsoft.Json;
@@ -33,7 +33,7 @@ namespace ShiftOS
public delegate void WindowDrawEventHandler(Form win);
//Event handler for passing a single control (e.g, a desktop panel) to the Lua API.
- public delegate void ControlDrawEventHandler(string ControlGUID);
+ public delegate void WidgetDrawEventHandler(string WidgetGUID);
//Lua events.
public event EmptyEventHandler OnDesktopReload;
@@ -49,7 +49,7 @@ namespace ShiftOS
public event WindowDrawEventHandler BorderReset;
public event ListEventHandler<DesktopIcon> DesktopIconsPopulated;
public event EmptyEventHandler OnUnityToggle;
- public event ControlDrawEventHandler OnDesktopPanelDraw;
+ public event WidgetDrawEventHandler OnDesktopPanelDraw;
public void InvokeWindowOp(string operation, Form win)
{
@@ -97,7 +97,7 @@ namespace ShiftOS
public ToolStripMenuItem AppLauncher { get { return this.ApplicationsToolStripMenuItem; } }
- public List<Control> CurrentWidgets = null;
+ public List<Widget> CurrentWidgets = null;
public void SetUnityMode()
{
@@ -133,7 +133,7 @@ namespace ShiftOS
switch (FinalMission.EndGameHandler.CurrentChoice)
{
case Choice.SideWithDevX:
- var t = new System.Windows.Forms.Timer();
+ var t = new ShiftUI.Timer();
t.Interval = 10000;
t.Tick += (object se, EventArgs ea) =>
{
@@ -171,13 +171,13 @@ namespace ShiftOS
private void ShiftOSDesktop_Load(object sender, EventArgs e)
{
this.pnlpanelbuttonholder.AutoSize = false;
- this.pnlpanelbuttonholder.ControlAdded += (o, a) =>
+ this.pnlpanelbuttonholder.WidgetAdded += (o, a) =>
{
- pnlpanelbuttonholder.Width += a.Control.Width + API.CurrentSkin.panelbuttongap;
+ pnlpanelbuttonholder.Width += a.Widget.Width + API.CurrentSkin.panelbuttongap;
};
- this.pnlpanelbuttonholder.ControlRemoved += (o, a) =>
+ this.pnlpanelbuttonholder.WidgetRemoved += (o, a) =>
{
- pnlpanelbuttonholder.Width -= a.Control.Width + API.CurrentSkin.panelbuttongap;
+ pnlpanelbuttonholder.Width -= a.Widget.Width + API.CurrentSkin.panelbuttongap;
};
Viruses.CheckForInfected();
@@ -186,11 +186,11 @@ namespace ShiftOS
this.WindowState = FormWindowState.Maximized;
this.KeyDown += (object s, KeyEventArgs ea) =>
{
- if (ea.KeyCode == Keys.T && ea.Control)
+ if (ea.KeyCode == Keys.T && ea.Widget)
{
InvokeCTRLT();
}
- else if (ea.KeyCode == Keys.D && ea.Control)
+ else if (ea.KeyCode == Keys.D && ea.Widget)
{
if (API.DeveloperMode == true)
{
@@ -208,9 +208,10 @@ namespace ShiftOS
CheckIfNew();
API.CurrentSession = this;
+ this.Location = new Point(0, 0);
- System.Windows.Forms.Timer clocktick = new System.Windows.Forms.Timer();
+ ShiftUI.Timer clocktick = new ShiftUI.Timer();
clocktick.Interval = 2;
clocktick.Tick += (object s, EventArgs a) =>
{
@@ -321,51 +322,59 @@ namespace ShiftOS
public FlowLayoutPanel PanelButtonHolder { get { return pnlpanelbuttonholder; } }
public Panel AppLauncherPanel { get { return applaunchermenuholder; } }
public Panel Clock { get { return timepanel; } }
- public Control SelectedObject = null;
+ public Widget SelectedObject = null;
private string SelectedIconName = null;
public void SetupDesktop()
{
- SetupRenderers();
- SetupDesktopPanel();
- SetupAppLauncher();
- SetupDesktopIcons();
- SetupGNOME2Elements();
- SetupPanelClock();
- SetupPanelButtons();
- CheckUnity();
- SetupWidgets();
- CheckForChristmas();
- //Set up the context menus.
- addDesktopPanelToolStripMenuItem.Visible = API.Upgrades["advanceddesktop"];
- widgetManagerToolStripMenuItem.Visible = API.Upgrades["advanceddesktop"];
- if (API.Upgrades["advanceddesktop"])
- {
- AppLauncherPanel.ContextMenuStrip = cbwidget;
- Clock.ContextMenuStrip = cbwidget;
- PanelButtonHolder.ContextMenuStrip = cbwidget;
- }
- else
- {
- AppLauncherPanel.ContextMenuStrip = null;
- Clock.ContextMenuStrip = null;
- PanelButtonHolder.ContextMenuStrip = null;
- }
- if (DesktopPanels != null) {
- foreach (var dp in DesktopPanels)
- {
- if (API.Upgrades["advanceddesktop"])
- {
- dp.ContextMenuStrip = cbdpanel;
- }
- else
- {
- dp.ContextMenuStrip = cbdpanel;
- }
- }
- }
- OnDesktopReload?.Invoke();
+ try
+ {
+ SetupRenderers();
+ SetupDesktopPanel();
+ SetupAppLauncher();
+ SetupDesktopIcons();
+ SetupGNOME2Elements();
+ SetupPanelClock();
+ SetupPanelButtons();
+ CheckUnity();
+ SetupWidgets();
+ CheckForChristmas();
+ //Set up the context menus.
+ addDesktopPanelToolStripMenuItem.Visible = API.Upgrades["advanceddesktop"];
+ widgetManagerToolStripMenuItem.Visible = API.Upgrades["advanceddesktop"];
+ if (API.Upgrades["advanceddesktop"])
+ {
+ AppLauncherPanel.ContextMenuStrip = cbwidget;
+ Clock.ContextMenuStrip = cbwidget;
+ PanelButtonHolder.ContextMenuStrip = cbwidget;
+ }
+ else
+ {
+ AppLauncherPanel.ContextMenuStrip = null;
+ Clock.ContextMenuStrip = null;
+ PanelButtonHolder.ContextMenuStrip = null;
+ }
+ if (DesktopPanels != null)
+ {
+ foreach (var dp in DesktopPanels)
+ {
+ if (API.Upgrades["advanceddesktop"])
+ {
+ dp.ContextMenuStrip = cbdpanel;
+ }
+ else
+ {
+ dp.ContextMenuStrip = cbdpanel;
+ }
+ }
+ }
+ OnDesktopReload?.Invoke();
+ }
+ catch (Exception catcherror)
+ {
+ Console.WriteLine(catcherror);
+ }
}
public void SetupWidgets()
@@ -392,8 +401,8 @@ namespace ShiftOS
wid.Dispose();
}
}
- WidgetsToMaintain = new List<Control>();
- Control ctrl = null;
+ WidgetsToMaintain = new List<Widget>();
+ Widget ctrl = null;
switch(w.Type)
{
case WidgetType.FreePanel:
@@ -411,7 +420,7 @@ namespace ShiftOS
}
if(ctrl != null)
{
- p.Controls.Add(ctrl);
+ p.Widgets.Add(ctrl);
ctrl.Show();
ctrl.BringToFront();
ctrl.Left = w.XLocation;
@@ -455,7 +464,7 @@ namespace ShiftOS
move.Click += (object s, EventArgs e) =>
{
ctrl.Tag = w;
- MovingControl = ctrl;
+ MovingWidget = ctrl;
};
ToolStripMenuItem move_to = (ToolStripMenuItem)cb_thiswidget.Items.Add("Move to...");
foreach(var dp in DesktopPanels)
@@ -503,9 +512,9 @@ namespace ShiftOS
}
- public List<Control> WidgetsToMaintain = null;
+ public List<Widget> WidgetsToMaintain = null;
- public Control MovingControl = null;
+ public Widget MovingWidget = null;
public bool WidgetContains(string Name)
{
@@ -543,7 +552,7 @@ namespace ShiftOS
{
flicons.ContextMenuStrip = cmbdesktopoptions;
DesktopIconManager.GetIcons();
- flicons.Controls.Clear();
+ flicons.Widgets.Clear();
foreach (DesktopIcon dl in DesktopIconManager.Icons)
{
dl.ContextMenuStrip = cmbfactions;
@@ -554,7 +563,7 @@ namespace ShiftOS
SelectedIconName = dl.IconName;
}
};
- flicons.Controls.Add(dl);
+ flicons.Widgets.Add(dl);
}
DesktopIconsPopulated?.Invoke(DesktopIconManager.Icons);
}
@@ -573,41 +582,27 @@ namespace ShiftOS
public void SetupDesktopPanel()
{
- if (DesktopPanels != null)
+ if(API.Upgrades["desktoppanel"])
{
- foreach (var pnl in DesktopPanels)
+ desktoppanel.BackColor = API.CurrentSkin.desktoppanelcolour;
+ desktoppanel.Height = API.CurrentSkin.desktoppanelheight;
+ switch(API.CurrentSkin.desktoppanelposition)
{
- if (this.Controls.Contains(pnl))
- {
- pnl.Hide();
- this.Controls.Remove(pnl);
- }
+ case "Top":
+ desktoppanel.Dock = DockStyle.Top;
+ break;
+ case "Bottom":
+ desktoppanel.Dock = DockStyle.Bottom;
+ break;
}
- }
- var old_list = new List<Skinning.DesktopPanel>();
- var dp = new Skinning.DesktopPanel();
- dp.Position = API.CurrentSkin.desktoppanelposition;
- dp.Height = API.CurrentSkin.desktoppanelheight;
- dp.BackgroundColor = API.CurrentSkin.desktoppanelcolour;
- dp.BackgroundImage = API.CurrentSkinImages.desktoppanel;
- old_list.Add(dp);
-
- if (API.CurrentSkin.DesktopPanels.Count == 0)
- {
- API.CurrentSkin.DesktopPanels = old_list;
- }
- if(API.Upgrades["advanceddesktop"])
- {
- SetupPanels(API.CurrentSkin.DesktopPanels);
+ desktoppanel.BackgroundImageLayout = (ImageLayout)API.CurrentSkin.desktoppanellayout;
+ desktoppanel.BackgroundImage = API.CurrentSkinImages.desktoppanel;
+
}
else
{
- if(API.Upgrades["desktoppanel"])
- {
- SetupPanels(old_list);
- }
+ desktoppanel.Hide();
}
- desktopappmenu.BackgroundImageLayout = (ImageLayout)API.CurrentSkin.applauncherlayout;
}
public void SetupPanels(List<Skinning.DesktopPanel> lst)
@@ -631,31 +626,31 @@ namespace ShiftOS
pnl.Height = dp.Height;
pnl.MouseMove += (object s, MouseEventArgs a) =>
{
- if (MovingControl != null)
+ if (MovingWidget != null)
{
var newloc = new Point(a.X + 15, 0);
var proper = pnl.PointToClient(newloc);
- MovingControl.Location = proper;
+ MovingWidget.Location = proper;
}
};
pnl.MouseDown += (object s, MouseEventArgs a) =>
{
- if (MovingControl != null)
+ if (MovingWidget != null)
{
if (a.Button == MouseButtons.Left)
{
- var w = (Skinning.DesktopWidget)MovingControl.Tag;
- w.XLocation = MovingControl.Left;
+ var w = (Skinning.DesktopWidget)MovingWidget.Tag;
+ w.XLocation = MovingWidget.Left;
Skinning.Utilities.saveskin();
}
else if (a.Button == MouseButtons.Left)
{
- var w = (Skinning.DesktopWidget)MovingControl.Tag;
- MovingControl.Left = w.XLocation;
+ var w = (Skinning.DesktopWidget)MovingWidget.Tag;
+ MovingWidget.Left = w.XLocation;
Skinning.Utilities.saveskin();
}
- MovingControl = null;
+ MovingWidget = null;
}
};
DesktopPanels.Add(pnl);
@@ -708,13 +703,13 @@ namespace ShiftOS
pnl.ContextMenuStrip = null;
}
pnl.Size = new Size(desktoppanel.Size.Width, dp.Height);
- this.Controls.Add(pnl);
+ this.Widgets.Add(pnl);
pnl.Show();
}
else
{
pnl.Hide();
- this.Controls.Remove(pnl);
+ this.Widgets.Remove(pnl);
}
string guid = Guid.NewGuid().ToString();
API.DEF_PanelGUIDs.Add(guid, pnl);
@@ -903,7 +898,7 @@ namespace ShiftOS
{
API.CurrentSkin.PanelButtonPosition = itm.Text;
}
- SelectedObject.Parent.Controls.Remove(SelectedObject);
+ SelectedObject.Parent.Widgets.Remove(SelectedObject);
SetupDesktopPanel();
Skinning.Utilities.saveskin();
}
@@ -990,22 +985,22 @@ namespace ShiftOS
}
}
- public void ChangePosition(Control ctrl, Panel newPanel)
+ public void ChangePosition(Widget ctrl, Panel newPanel)
{
try {
- ctrl.Parent.Controls.Remove(ctrl);
- newPanel.Controls.Add(ctrl);
+ ctrl.Parent.Widgets.Remove(ctrl);
+ newPanel.Widgets.Add(ctrl);
}
catch
{
- newPanel.Controls.Add(ctrl);
+ newPanel.Widgets.Add(ctrl);
}
ctrl.BringToFront();
}
public void SetupPanelButtons()
{
- pnlpanelbuttonholder.Controls.Clear();
+ pnlpanelbuttonholder.Widgets.Clear();
if (API.Upgrades["panelbuttons"] == true)
{
foreach (PanelButton pbtn in API.PanelButtons)
@@ -1025,7 +1020,7 @@ namespace ShiftOS
setuppanelbuttonicons(ref pb, pbtn.Icon);
- pnlpanelbuttonholder.Controls.Add(pnl);
+ pnlpanelbuttonholder.Widgets.Add(pnl);
pnl.ContextMenuStrip = null;
pnl.Show();
pnl.Click += new EventHandler(this.PanelButton_Click);
@@ -1049,8 +1044,8 @@ namespace ShiftOS
public void setpanelbuttonappearnce(ref Panel panelbutton, ref PictureBox icon, ref Label text)
{
- panelbutton.Controls.Add(text);
- panelbutton.Controls.Add(icon);
+ panelbutton.Widgets.Add(text);
+ panelbutton.Widgets.Add(icon);
text.Show();
if (API.Upgrades["appicons"] == true)
{
@@ -1085,24 +1080,24 @@ namespace ShiftOS
{
if (API.Upgrades["usefulpanelbuttons"])
{
- Control ctrl = (Control)sender;
- try
- {
- PanelButton pbtn = (PanelButton)ctrl.Tag;
- var frm = pbtn.FormToManage;
- if(frm.Left < Screen.PrimaryScreen.Bounds.Width)
- {
- API.MinimizeForm(frm);
- }
- else
- {
- API.ToggleMinimized(frm);
- }
- }
- catch
- {
-
- }
+ Widget ctrl = (Widget)sender;
+ try
+ {
+ PanelButton pbtn = (PanelButton)ctrl.Tag;
+ var frm = pbtn.FormToManage;
+ if (frm.Left < Screen.PrimaryScreen.Bounds.Width)
+ {
+ API.MinimizeForm(frm);
+ }
+ else
+ {
+ API.ToggleMinimized(frm);
+ }
+ }
+ catch (Exception catcherror)
+ {
+ Console.WriteLine(catcherror);
+ }
}
}
@@ -1148,7 +1143,7 @@ namespace ShiftOS
n.Location = new Point(this.Width - n.Width, this.Height - n.Height - desktoppanel.Height);
break;
}
- this.Controls.Add(n);
+ this.Widgets.Add(n);
n.Show();
n.BringToFront();
}
@@ -1334,113 +1329,111 @@ namespace ShiftOS
public static List<DesktopIcon> Icons = null;
public static List<IconModel> Models = null;
- public static void GetIcons()
- {
- Icons = new List<DesktopIcon>();
- Models = new List<IconModel>();
- API.GetAppLauncherItems();
- if (!Directory.Exists(Paths.Desktop))
- {
- Directory.CreateDirectory(Paths.Desktop);
- }
- else
- {
- foreach (string dir in Directory.GetDirectories(Paths.Desktop))
- {
- //Get dir info
- var dinf = new DirectoryInfo(dir);
- //Create new IconModel
- var m = new IconModel();
- //Set name to dir name
- m.Name = dinf.Name;
- //Set type to Directory
- m.Type = IconType.Directory;
- //Set lua to open directory in File Skimmer
- m.Lua = $"fileskimmer('/Home/Desktop/{dinf.Name}')";
- Models.Add(m);
- }
- foreach (string file in Directory.GetFiles(Paths.Desktop))
- {
- //Get file info
- var finf = new FileInfo(file);
- //Create new IconModel
- var icm = new IconModel();
- //Set IconModel name to filename
- icm.Name = finf.Name;
- //Set IconModel's type based on file extension
- switch (finf.Extension.ToLower()) //Make the string lower-case for ease of use.
- {
- case ".desktop":
- //Desktop script.
- icm.Type = IconType.Script;
- icm.Lua = File.ReadAllText(finf.FullName); //The Lua that is to be ran by this script is in the file.
- break;
- case ".sct":
- //Desktop Shortcut - NYI
- break;
- default:
- //File.
- icm.Type = IconType.File;
- icm.Lua = $"fopen('/Home/Desktop/{finf.Name}')";
- break;
- }
- Models.Add(icm);
- }
- }
-
- foreach(IconModel m in Models)
- {
- var d = new DesktopIcon();
- d.IconName = m.Name;
- d.LuaAction = m.Lua;
- switch(m.Type)
- {
- case IconType.Directory:
- d.Icon = API.GetIcon("Folder");
- break;
- default:
- var finf = new FileInfo(Paths.Desktop + d.IconName);
- switch(finf.Extension)
- {
- case ".txt":
- case ".doc":
- case ".owd":
- case ".docx":
- d.Icon = API.GetIcon("TextFile");
- break;
- case ".skn":
- case ".spk":
- d.Icon = API.GetIcon("SkinFile");
- break;
- case ".saa":
- d.Icon = API.GetIcon("SAAFile");
- break;
- case ".pkg":
- case ".stp":
- d.Icon = API.GetIcon("SetupPackage");
- break;
- default:
- d.Icon = API.GetIcon("UnrecognizedFile");
- break;
- }
- break;
- }
- Icons.Add(d);
- }
- foreach (ApplauncherItem al in API.AppLauncherItems)
- {
- if (al.Display == true)
- {
- var dl = new DesktopIcon();
- dl.Icon = al.Icon;
- dl.IconName = al.Name;
- dl.LuaAction = al.Lua;
- Icons.Add(dl);
- }
- }
-
- }
-
+ public static void GetIcons()
+ {
+ Icons = new List<DesktopIcon>();
+ Models = new List<IconModel>();
+ API.GetAppLauncherItems();
+ if (!Directory.Exists(Paths.Desktop))
+ {
+ Directory.CreateDirectory(Paths.Desktop);
+ }
+ else
+ {
+ foreach (string dir in Directory.GetDirectories(Paths.Desktop))
+ {
+ //Get dir info
+ var dinf = new DirectoryInfo(dir);
+ //Create new IconModel
+ var m = new IconModel();
+ //Set name to dir name
+ m.Name = dinf.Name;
+ //Set type to Directory
+ m.Type = IconType.Directory;
+ //Set lua to open directory in File Skimmer
+ m.Lua = $"fileskimmer('/Home/Desktop/{dinf.Name}')";
+ Models.Add(m);
+ }
+ foreach (string file in Directory.GetFiles(Paths.Desktop))
+ {
+ //Get file info
+ var finf = new FileInfo(file);
+ //Create new IconModel
+ var icm = new IconModel();
+ //Set IconModel name to filename
+ icm.Name = finf.Name;
+ //Set IconModel's type based on file extension
+ switch (finf.Extension.ToLower()) //Make the string lower-case for ease of use.
+ {
+ case ".desktop":
+ //Desktop script.
+ icm.Type = IconType.Script;
+ icm.Lua = File.ReadAllText(finf.FullName); //The Lua that is to be ran by this script is in the file.
+ break;
+ case ".sct":
+ //Desktop Shortcut - NYI
+ break;
+ default:
+ //File.
+ icm.Type = IconType.File;
+ icm.Lua = $"fopen('/Home/Desktop/{finf.Name}')";
+ break;
+ }
+ Models.Add(icm);
+ }
+ }
+
+ foreach (IconModel m in Models)
+ {
+ var d = new DesktopIcon();
+ d.IconName = m.Name;
+ d.LuaAction = m.Lua;
+ switch (m.Type)
+ {
+ case IconType.Directory:
+ d.Icon = API.GetIcon("Folder");
+ break;
+ default:
+ var finf = new FileInfo(Paths.Desktop + d.IconName);
+ switch (finf.Extension)
+ {
+ case ".txt":
+ case ".doc":
+ case ".owd":
+ case ".docx":
+ d.Icon = API.GetIcon("TextFile");
+ break;
+ case ".skn":
+ case ".spk":
+ d.Icon = API.GetIcon("SkinFile");
+ break;
+ case ".saa":
+ d.Icon = API.GetIcon("SAAFile");
+ break;
+ case ".pkg":
+ case ".stp":
+ d.Icon = API.GetIcon("SetupPackage");
+ break;
+ default:
+ d.Icon = API.GetIcon("UnrecognizedFile");
+ break;
+ }
+ break;
+ }
+ Icons.Add(d);
+ }
+ foreach (ApplauncherItem al in API.AppLauncherItems)
+ {
+ if (al.Display == true)
+ {
+ var dl = new DesktopIcon();
+ dl.Icon = al.Icon;
+ dl.IconName = al.Name;
+ dl.LuaAction = al.Lua;
+ Icons.Add(dl);
+ }
+ }
+ }
public class IconModel
{
public string Name { get; set; }