From 10e3a9da9621f90111cba6f2891b55ce16ec8cf3 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Tue, 24 Mar 2026 20:17:10 +0800 Subject: [PATCH] =?UTF-8?q?Files=E5=A2=9E=E5=BC=BA=E6=89=93=E5=BC=80?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BuildTime.txt | 2 +- GitCommit.txt | 2 +- Gui/Apps/CodeStudio/CodeStudio.cs | 10 ++++ Gui/Apps/Files.cs | 83 +++++++++++++++++++++++++++++-- Gui/Apps/Settings.cs | 78 ++++++++++++++++++++++++++++- 5 files changed, 167 insertions(+), 8 deletions(-) diff --git a/BuildTime.txt b/BuildTime.txt index bdb9053..672aed1 100644 --- a/BuildTime.txt +++ b/BuildTime.txt @@ -1 +1 @@ -2026-03-24 18:59:31 \ No newline at end of file +2026-03-24 20:13:51 \ No newline at end of file diff --git a/GitCommit.txt b/GitCommit.txt index 207462b..243dab1 100644 --- a/GitCommit.txt +++ b/GitCommit.txt @@ -1 +1 @@ -d044e97 \ No newline at end of file +4dd47bf \ No newline at end of file diff --git a/Gui/Apps/CodeStudio/CodeStudio.cs b/Gui/Apps/CodeStudio/CodeStudio.cs index f244f76..bda3a5f 100644 --- a/Gui/Apps/CodeStudio/CodeStudio.cs +++ b/Gui/Apps/CodeStudio/CodeStudio.cs @@ -24,6 +24,11 @@ namespace CMLeonOS.Gui.Apps.CodeStudio internal class CodeStudio : Process { internal CodeStudio() : base("CodeStudio", ProcessType.Application) { } + + internal CodeStudio(string path) : base("CodeStudio", ProcessType.Application) + { + initialPath = path; + } Window splash; @@ -34,6 +39,7 @@ namespace CMLeonOS.Gui.Apps.CodeStudio private static Bitmap splashBitmap = new Bitmap(_splashBytes); private Ide ide; + private string initialPath = null; private bool ideCreated = false; @@ -55,6 +61,10 @@ namespace CMLeonOS.Gui.Apps.CodeStudio { ide = new Ide(this, wm); ide.Start(); + if (!string.IsNullOrWhiteSpace(initialPath)) + { + ide.Open(initialPath); + } wm.RemoveWindow(splash); ideCreated = true; } diff --git a/Gui/Apps/Files.cs b/Gui/Apps/Files.cs index 85c453d..61f9798 100644 --- a/Gui/Apps/Files.cs +++ b/Gui/Apps/Files.cs @@ -236,13 +236,19 @@ namespace CMLeonOS.Gui.Apps string extension = Path.GetExtension(path).ToLower(); if (extension == ".txt" || extension == ".md") { - var notepad = new Notepad(path); - var metadata = AppManager.GetAppMetadata("Notepad"); - metadata.Start(); + ProcessManager.AddProcess(this, new Notepad(path)).Start(); + } + else if (extension == ".lua") + { + ProcessManager.AddProcess(this, new CodeStudio.CodeStudio(path)).Start(); + } + else if (extension == ".bmp") + { + ProcessManager.AddProcess(this, new ImageViewer(path)).Start(); } else { - Logger.Logger.Instance.Warning("Files", $"Cannot open file: {path}"); + ShowOpenWithPrompt(path); } } catch (Exception ex) @@ -253,6 +259,75 @@ namespace CMLeonOS.Gui.Apps } } + private void OpenWithApp(string path, string appName) + { + switch (appName) + { + case "Notepad": + ProcessManager.AddProcess(this, new Notepad(path)).Start(); + break; + case "CodeStudio": + ProcessManager.AddProcess(this, new CodeStudio.CodeStudio(path)).Start(); + break; + case "Image Viewer": + ProcessManager.AddProcess(this, new ImageViewer(path)).Start(); + break; + default: + Logger.Logger.Instance.Warning("Files", $"Unsupported open-with app: {appName}"); + break; + } + } + + private void ShowOpenWithPrompt(string path) + { + AppWindow openWithWindow = new AppWindow(this, 320, 240, 300, 176); + openWithWindow.Title = "Open With"; + openWithWindow.Icon = AppManager.DefaultAppIcon; + wm.AddWindow(openWithWindow); + + openWithWindow.Clear(UITheme.Surface); + openWithWindow.DrawRectangle(0, 0, openWithWindow.Width, openWithWindow.Height, UITheme.SurfaceBorder); + openWithWindow.DrawString("Open this file with:", UITheme.TextPrimary, 12, 12); + openWithWindow.DrawString(Path.GetFileName(path), UITheme.TextSecondary, 12, 32); + + Button notepadButton = new Button(openWithWindow, 12, 68, 84, 24); + notepadButton.Text = "Notepad"; + notepadButton.OnClick = (_, _) => + { + wm.RemoveWindow(openWithWindow); + OpenWithApp(path, "Notepad"); + }; + wm.AddWindow(notepadButton); + + Button codeStudioButton = new Button(openWithWindow, 108, 68, 84, 24); + codeStudioButton.Text = "CodeStudio"; + codeStudioButton.OnClick = (_, _) => + { + wm.RemoveWindow(openWithWindow); + OpenWithApp(path, "CodeStudio"); + }; + wm.AddWindow(codeStudioButton); + + Button imageViewerButton = new Button(openWithWindow, 204, 68, 84, 24); + imageViewerButton.Text = "Image"; + imageViewerButton.OnClick = (_, _) => + { + wm.RemoveWindow(openWithWindow); + OpenWithApp(path, "Image Viewer"); + }; + wm.AddWindow(imageViewerButton); + + Button cancelButton = new Button(openWithWindow, openWithWindow.Width - 80 - 12, openWithWindow.Height - 20 - 12, 80, 20); + cancelButton.Text = "Cancel"; + cancelButton.OnClick = (_, _) => + { + wm.RemoveWindow(openWithWindow); + }; + wm.AddWindow(cancelButton); + + wm.Update(openWithWindow); + } + private void ShortcutsTableCellSelected(int index) { if (index != -1) diff --git a/Gui/Apps/Settings.cs b/Gui/Apps/Settings.cs index 94d9912..b5c7250 100644 --- a/Gui/Apps/Settings.cs +++ b/Gui/Apps/Settings.cs @@ -294,10 +294,84 @@ namespace CMLeonOS.Gui.Apps currentCategoryWindow = users; users.DrawString("Users", Color.DarkBlue, 12, 12); users.DrawImageAlpha(Icons.Icon_Info, 12, window.Height - 16 - 12); - users.DrawString("Double-click on a user for info.", Color.Gray, 36, window.Height - 16 - 12); + users.DrawString("Double-click a user for details.", Color.Gray, 36, window.Height - 16 - 12); wm.AddWindow(users); - Table usersTable = new Table(users, 12, 40, users.Width - 24, users.Height - 40 - 12 - 16 - 12); + bool canManageUsers = UserSystem.CurrentLoggedInUser != null && UserSystem.CurrentLoggedInUser.Admin; + Table usersTable = null; + + if (canManageUsers) + { + Button createUser = new Button(users, 12, 40, 108, 22); + createUser.Text = "Create User"; + createUser.OnClick = (_, _) => + { + PromptBox promptBox = new PromptBox(this, "Create User", "Enter username and password.\nFormat: username password", "newuser password", (string value) => + { + string[] parts = (value ?? string.Empty).Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + if (parts.Length < 2) + { + ShowMessage("Users", "Use the format: username password"); + return; + } + + bool created = UserManager.AddUser(parts[0], parts[1], false); + if (!created) + { + ShowMessage("Users", "Failed to create user."); + return; + } + + ShowMessage("Users", $"User '{parts[0]}' created."); + ShowUsersCategory(); + }); + promptBox.Show(); + }; + wm.AddWindow(createUser); + + Button deleteUser = new Button(users, 130, 40, 108, 22); + deleteUser.Text = "Delete User"; + deleteUser.OnClick = (_, _) => + { + if (usersTable.SelectedCellIndex == -1) + { + ShowMessage("Users", "Select a user first."); + return; + } + + User selectedUser = (User)usersTable.Cells[usersTable.SelectedCellIndex].Tag; + if (selectedUser == null) + { + ShowMessage("Users", "Select a valid user first."); + return; + } + + if (UserSystem.CurrentLoggedInUser != null + && selectedUser.Username.Equals(UserSystem.CurrentLoggedInUser.Username, StringComparison.OrdinalIgnoreCase)) + { + ShowMessage("Users", "You cannot delete the current logged in user."); + return; + } + + bool deleted = UserManager.RemoveUser(selectedUser.Username); + if (!deleted) + { + ShowMessage("Users", "Failed to delete user."); + return; + } + + ShowMessage("Users", $"User '{selectedUser.Username}' deleted."); + ShowUsersCategory(); + }; + wm.AddWindow(deleteUser); + } + else + { + users.DrawString("Only administrators can create or delete users.", Color.Gray, 12, 44); + } + + int tableY = canManageUsers ? 74 : 40; + usersTable = new Table(users, 12, tableY, users.Width - 24, users.Height - tableY - 12 - 16 - 12); foreach (User user in UserSystem.GetUsers()) { usersTable.Cells.Add(new TableCell(user.Admin ? Icons.Icon_Admin : Icons.Icon_User, user.Username, tag: user));