mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-04-21 19:24:00 +00:00
Files增强打开文件
This commit is contained in:
@@ -1 +1 @@
|
||||
2026-03-24 18:59:31
|
||||
2026-03-24 20:13:51
|
||||
@@ -1 +1 @@
|
||||
d044e97
|
||||
4dd47bf
|
||||
@@ -25,6 +25,11 @@ namespace CMLeonOS.Gui.Apps.CodeStudio
|
||||
{
|
||||
internal CodeStudio() : base("CodeStudio", ProcessType.Application) { }
|
||||
|
||||
internal CodeStudio(string path) : base("CodeStudio", ProcessType.Application)
|
||||
{
|
||||
initialPath = path;
|
||||
}
|
||||
|
||||
Window splash;
|
||||
|
||||
WindowManager wm = ProcessManager.GetProcess<WindowManager>();
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user