Skip to content

Commit c5e35d0

Browse files
committed
Release for beta version
1 parent 116202c commit c5e35d0

13 files changed

+1370
-636
lines changed

ActionCodexEditor.Dialogs.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using Terminal.Gui;
2+
3+
namespace ActionCodex
4+
{
5+
public partial class ActionCodexEditor
6+
{
7+
private void ShowAbout()
8+
{
9+
MessageBox.Query(
10+
GetLocalizedString("AboutTitle"),
11+
$"{GetLocalizedString("AboutVersion")}\n\n" +
12+
$"{GetLocalizedString("AboutGithub")}\n" +
13+
$"{GetLocalizedString("AboutCopyright")}",
14+
GetLocalizedString("MsgOK"));
15+
}
16+
17+
private void ShowShortcuts()
18+
{
19+
var shortcuts = new Dialog(GetLocalizedString("ShortcutsTitle"))
20+
{
21+
Width = 50,
22+
Height = 20
23+
};
24+
25+
var text = new Label
26+
{
27+
X = 1,
28+
Y = 1,
29+
Text =
30+
$"{GetLocalizedString("ShortcutsFileOps")}\n" +
31+
$" {GetLocalizedString("ShortcutsNew")}\n" +
32+
$" {GetLocalizedString("ShortcutsOpen")}\n" +
33+
$" {GetLocalizedString("ShortcutsSave")}\n" +
34+
$" {GetLocalizedString("ShortcutsClose")}\n" +
35+
$" {GetLocalizedString("ShortcutsQuit")}\n\n" +
36+
$"{GetLocalizedString("ShortcutsEditing")}\n" +
37+
$" {GetLocalizedString("ShortcutsCopy")}\n" +
38+
$" {GetLocalizedString("ShortcutsCut")}\n" +
39+
$" {GetLocalizedString("ShortcutsPaste")}\n" +
40+
$" {GetLocalizedString("ShortcutsDelete")}\n" +
41+
$" {GetLocalizedString("ShortcutsSelectAll")}\n\n" +
42+
$"{GetLocalizedString("ShortcutsNavigation")}\n" +
43+
$" {GetLocalizedString("ShortcutsArrow")}\n" +
44+
$" {GetLocalizedString("ShortcutsHomeEnd")}\n" +
45+
$" {GetLocalizedString("ShortcutsPageUpDown")}\n\n" +
46+
$"{GetLocalizedString("ShortcutsOther")}\n" +
47+
$" {GetLocalizedString("ShortcutsF1")}\n" +
48+
$" {GetLocalizedString("ShortcutsTab")}"
49+
};
50+
51+
shortcuts.Add(text);
52+
53+
var okBtn = new Button(GetLocalizedString("MsgOK"))
54+
{
55+
X = Pos.Center(),
56+
Y = Pos.AnchorEnd(2)
57+
};
58+
okBtn.Clicked += () => Application.RequestStop();
59+
shortcuts.Add(okBtn);
60+
61+
Application.Run(shortcuts);
62+
}
63+
64+
private void ShowError(string message)
65+
{
66+
MessageBox.ErrorQuery(GetLocalizedString("MsgError"), message, GetLocalizedString("MsgOK"));
67+
}
68+
69+
private bool CheckUnsavedChanges(TabContext? ctx = null)
70+
{
71+
if (ctx == null) ctx = GetCurrentTabContext();
72+
if (ctx == null) return true;
73+
74+
if (ctx.IsModified)
75+
{
76+
int result = MessageBox.Query(
77+
GetLocalizedString("MsgUnsavedChanges"),
78+
$"'{Path.GetFileName(ctx.FilePath)}' {GetLocalizedString("MsgUnsavedChanges")}",
79+
GetLocalizedString("MsgSave"),
80+
GetLocalizedString("MsgDiscard"),
81+
GetLocalizedString("MsgCancel"));
82+
83+
switch (result)
84+
{
85+
case 0:
86+
SaveFile();
87+
return !ctx.IsModified;
88+
case 1:
89+
return true;
90+
default:
91+
return false;
92+
}
93+
}
94+
return true;
95+
}
96+
}
97+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Terminal.Gui;
2+
3+
namespace ActionCodex
4+
{
5+
public partial class ActionCodexEditor
6+
{
7+
private void HandleKeyDown(View.KeyEventEventArgs e, TabContext ctx)
8+
{
9+
if ((e.KeyEvent.IsCtrl && e.KeyEvent.Key == Key.S))
10+
{
11+
SaveFile();
12+
e.Handled = true;
13+
}
14+
else if ((e.KeyEvent.IsCtrl && e.KeyEvent.Key == Key.N))
15+
{
16+
NewFile();
17+
e.Handled = true;
18+
}
19+
else if ((e.KeyEvent.IsCtrl && e.KeyEvent.Key == Key.O))
20+
{
21+
OpenFile();
22+
e.Handled = true;
23+
}
24+
else if ((e.KeyEvent.IsCtrl && e.KeyEvent.Key == Key.W))
25+
{
26+
CloseFile();
27+
e.Handled = true;
28+
}
29+
}
30+
31+
private void ToggleWordWrap()
32+
{
33+
var ctx = GetCurrentTabContext();
34+
if (ctx != null)
35+
{
36+
ctx.Editor.WordWrap = !ctx.Editor.WordWrap;
37+
if (statusLabel != null)
38+
statusLabel.Text = ctx.Editor.WordWrap ? "Word wrap ON" : "Word wrap OFF";
39+
}
40+
}
41+
}
42+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
using Terminal.Gui;
2+
3+
namespace ActionCodex
4+
{
5+
public partial class ActionCodexEditor
6+
{
7+
private void NewFile()
8+
{
9+
CreateNewTab();
10+
if (statusLabel != null)
11+
statusLabel.Text = GetLocalizedString("StatusNew");
12+
}
13+
14+
private void OpenFile()
15+
{
16+
var dialog = new OpenDialog(GetLocalizedString("MenuOpen"), GetLocalizedString("MenuOpen"))
17+
{
18+
AllowsMultipleSelection = false,
19+
CanChooseDirectories = false,
20+
CanChooseFiles = true
21+
};
22+
23+
Application.Run(dialog);
24+
25+
if (!dialog.Canceled && dialog.FilePaths != null && dialog.FilePaths.Count > 0)
26+
{
27+
try
28+
{
29+
string? filePath = dialog.FilePaths[0]?.ToString();
30+
if (string.IsNullOrEmpty(filePath)) return;
31+
32+
var existingTab = openTabs.Values.FirstOrDefault(t => t.FilePath == filePath);
33+
if (existingTab != null)
34+
{
35+
if (tabView != null) tabView.SelectedTab = existingTab.Tab;
36+
return;
37+
}
38+
39+
string content = File.ReadAllText(filePath);
40+
41+
var currentCtx = GetCurrentTabContext();
42+
if (currentCtx != null && currentCtx.FilePath.StartsWith("Untitled") && !currentCtx.IsModified)
43+
{
44+
tabView?.RemoveTab(currentCtx.Tab);
45+
openTabs.Remove(currentCtx.Tab);
46+
}
47+
48+
CreateNewTab(filePath, content);
49+
50+
if (statusLabel != null)
51+
statusLabel.Text = $"Loaded {Path.GetFileName(filePath)}";
52+
}
53+
catch (Exception ex)
54+
{
55+
ShowError($"Error opening file: {ex.Message}");
56+
}
57+
}
58+
}
59+
60+
private void SaveFile()
61+
{
62+
var ctx = GetCurrentTabContext();
63+
if (ctx == null) return;
64+
65+
if (ctx.FilePath.StartsWith("Untitled"))
66+
{
67+
SaveFileAs();
68+
}
69+
else
70+
{
71+
try
72+
{
73+
File.WriteAllText(ctx.FilePath, ctx.Editor.Text.ToString());
74+
ctx.IsModified = false;
75+
UpdateTitle();
76+
if (statusLabel != null)
77+
statusLabel.Text = $"Saved {Path.GetFileName(ctx.FilePath)}";
78+
}
79+
catch (Exception ex)
80+
{
81+
ShowError($"Error saving file: {ex.Message}");
82+
}
83+
}
84+
}
85+
86+
private void SaveFileAs()
87+
{
88+
var ctx = GetCurrentTabContext();
89+
if (ctx == null) return;
90+
91+
var dialog = new SaveDialog(GetLocalizedString("MenuSaveAs"), GetLocalizedString("MenuSaveAs"))
92+
{
93+
AllowedFileTypes = new string[] { ".txt", ".cs", ".vb" },
94+
CanCreateDirectories = true
95+
};
96+
97+
Application.Run(dialog);
98+
99+
if (!dialog.Canceled && dialog.FilePath != null && !string.IsNullOrEmpty(dialog.FilePath.ToString()))
100+
{
101+
try
102+
{
103+
string filePath = dialog.FilePath.ToString() ?? "";
104+
if (string.IsNullOrEmpty(filePath)) return;
105+
106+
if (!filePath.Contains("."))
107+
{
108+
filePath += ".txt";
109+
}
110+
111+
File.WriteAllText(filePath, ctx.Editor.Text.ToString());
112+
ctx.FilePath = filePath;
113+
ctx.IsModified = false;
114+
UpdateTitle();
115+
116+
if (statusLabel != null)
117+
statusLabel.Text = $"Saved as {Path.GetFileName(ctx.FilePath)}";
118+
}
119+
catch (Exception ex)
120+
{
121+
ShowError($"Error saving file: {ex.Message}");
122+
}
123+
}
124+
}
125+
126+
private void CloseFile()
127+
{
128+
var ctx = GetCurrentTabContext();
129+
if (ctx == null) return;
130+
131+
if (CheckUnsavedChanges(ctx))
132+
{
133+
tabView?.RemoveTab(ctx.Tab);
134+
openTabs.Remove(ctx.Tab);
135+
136+
if (openTabs.Count == 0)
137+
{
138+
CreateNewTab();
139+
}
140+
141+
UpdateTitle();
142+
if (statusLabel != null)
143+
statusLabel.Text = GetLocalizedString("MenuCloseTab");
144+
}
145+
}
146+
147+
private void Quit()
148+
{
149+
if (CheckAllUnsavedChanges())
150+
{
151+
Application.RequestStop();
152+
}
153+
}
154+
}
155+
}

0 commit comments

Comments
 (0)