aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend/Apps/FileSkimmer.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-07-17 14:34:59 -0400
committerMichael <[email protected]>2017-07-17 14:34:59 -0400
commita0ee79dbcd26a8f07d493a7e993cbaf0d02e44db (patch)
treed974220621e6cfcfe745c2825149ca370e3a7aab /ShiftOS.Frontend/Apps/FileSkimmer.cs
parente929a9f5105c00b0a3a2b4e75a876bbb95bbfa7b (diff)
downloadshiftos_thereturn-a0ee79dbcd26a8f07d493a7e993cbaf0d02e44db.tar.gz
shiftos_thereturn-a0ee79dbcd26a8f07d493a7e993cbaf0d02e44db.tar.bz2
shiftos_thereturn-a0ee79dbcd26a8f07d493a7e993cbaf0d02e44db.zip
Hacking, barebones fskimmer, double clicking
Diffstat (limited to 'ShiftOS.Frontend/Apps/FileSkimmer.cs')
-rw-r--r--ShiftOS.Frontend/Apps/FileSkimmer.cs151
1 files changed, 151 insertions, 0 deletions
diff --git a/ShiftOS.Frontend/Apps/FileSkimmer.cs b/ShiftOS.Frontend/Apps/FileSkimmer.cs
new file mode 100644
index 0000000..29c5802
--- /dev/null
+++ b/ShiftOS.Frontend/Apps/FileSkimmer.cs
@@ -0,0 +1,151 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ShiftOS.Engine;
+using static ShiftOS.Objects.ShiftFS.Utils;
+
+namespace ShiftOS.Frontend.Apps
+{
+ [WinOpen("fileskimmer")]
+ [Launcher("File Skimmer", false, null, "System")]
+ [DefaultTitle("File Skimmer")]
+ public class FileSkimmer : GUI.Control, IShiftOSWindow
+ {
+ private string _currentdirectory = "0:";
+ private const string SD_SYSTEM = "__system";
+ private GUI.ListBox _fList = null;
+ private GUI.TextControl _currentdirtext = null;
+
+ public void OnLoad()
+ {
+ Width = 720;
+ Height = 480;
+ _fList = new GUI.ListBox();
+ _fList.KeyEvent += (e) =>
+ {
+ if(e.Key == Microsoft.Xna.Framework.Input.Keys.Enter)
+ {
+ Navigate(_fList.SelectedItem.ToString());
+ }
+ };
+ _fList.DoubleClick += () =>
+ {
+ try
+ {
+ Navigate(_fList.SelectedItem.ToString());
+ }
+ catch { }
+ };
+ AddControl(_fList);
+ _currentdirtext = new GUI.TextControl();
+ _currentdirtext.AutoSize = true;
+ AddControl(_currentdirtext);
+ ResetList();
+ }
+
+ public void Navigate(string relativepath)
+ {
+ if (relativepath == "Up one...")
+ {
+ if (_currentdirectory.Contains('/'))
+ {
+ int _index = _currentdirectory.LastIndexOf('/');
+ int _len = _currentdirectory.Length - _index;
+ _currentdirectory = _currentdirectory.Remove(_index, _len);
+ ResetList();
+ }
+ else
+ {
+ _currentdirectory = SD_SYSTEM;
+ ResetList();
+ }
+ return;
+ }
+
+ string path = "";
+ if (_currentdirectory == SD_SYSTEM)
+ path = relativepath;
+ else
+ path = _currentdirectory + "/" + relativepath;
+ if (DirectoryExists(path))
+ {
+ _currentdirectory = path;
+ ResetList();
+ }
+ else if (FileExists(path))
+ {
+ if (!FileSkimmerBackend.OpenFile(path))
+ {
+ Engine.Infobox.Show("File Skimmer can't open this file!", "A program that can open files of this type was not found on your computer.");
+ }
+ }
+ }
+
+ public void OnSkinLoad()
+ {
+ _currentdirtext.Font = SkinEngine.LoadedSkin.Header3Font;
+ }
+
+ public bool OnUnload()
+ {
+ return true;
+ }
+
+ public void OnUpgrade()
+ {
+ }
+
+ public void ResetList()
+ {
+ if (_currentdirectory == SD_SYSTEM)
+ _currentdirtext.Text = "My storage drives";
+ else
+ _currentdirtext.Text = _currentdirectory;
+
+ _fList.ClearItems();
+ if (_currentdirectory != SD_SYSTEM)
+ _fList.AddItem("Up one...");
+
+ if(_currentdirectory == SD_SYSTEM)
+ {
+ foreach(var mount in Mounts)
+ {
+ _fList.AddItem(Mounts.IndexOf(mount) + ":");
+ }
+ }
+ else
+ {
+ foreach(var dir in GetDirectories(_currentdirectory))
+ {
+ var dinf = GetDirectoryInfo(dir);
+ _fList.AddItem(dinf.Name);
+ }
+ foreach (var dir in GetFiles(_currentdirectory))
+ {
+ var dinf = GetFileInfo(dir);
+ _fList.AddItem(dinf.Name);
+ }
+
+ }
+ InvalidateTopLevel();
+ }
+
+
+ protected override void OnLayout()
+ {
+ try
+ {
+ _currentdirtext.Layout();
+ _fList.X = 0;
+ _fList.Y = 0;
+ _fList.Width = Width;
+ _fList.Height = Height - _currentdirtext.Height;
+ _currentdirtext.X = (Width - _currentdirtext.Width) / 2;
+ _currentdirtext.Y = _fList.Height;
+ }
+ catch { }
+ }
+ }
+}