FileItem will no longer open more than 1 tab for a file.
Added Ctrl+S shortcut in BaseEditor.
This commit is contained in:
@@ -7,5 +7,13 @@
|
|||||||
x:Class="Progrart.Controls.BaseEditor">
|
x:Class="Progrart.Controls.BaseEditor">
|
||||||
<avaloniaedit:TextEditor Name="CodeEditBox" Text="" SyntaxHighlighting="JavaScript"
|
<avaloniaedit:TextEditor Name="CodeEditBox" Text="" SyntaxHighlighting="JavaScript"
|
||||||
ShowLineNumbers="True"
|
ShowLineNumbers="True"
|
||||||
FontFamily="Sarasa Mono Slab CL,Cascadia Code,Consolas,Menlo,Monospace"/>
|
FontFamily="Sarasa Mono Slab CL,Cascadia Code,Consolas,Menlo,Monospace">
|
||||||
|
<avaloniaedit:TextEditor.ContextMenu>
|
||||||
|
<ContextMenu>
|
||||||
|
<MenuItem Name="Copy" Click="Copy_Click"/>
|
||||||
|
<MenuItem Name="Cut" Click="Cut_Click"/>
|
||||||
|
<MenuItem Name="Paste" Click="Paste_Click"/>
|
||||||
|
</ContextMenu>
|
||||||
|
</avaloniaedit:TextEditor.ContextMenu>
|
||||||
|
</avaloniaedit:TextEditor>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using AvaloniaEdit;
|
||||||
using AvaloniaEdit.TextMate;
|
using AvaloniaEdit.TextMate;
|
||||||
|
using System;
|
||||||
|
using System.Windows.Input;
|
||||||
using TextMateSharp.Grammars;
|
using TextMateSharp.Grammars;
|
||||||
|
|
||||||
namespace Progrart.Controls;
|
namespace Progrart.Controls;
|
||||||
@@ -15,6 +19,7 @@ public partial class BaseEditor : UserControl
|
|||||||
get => CodeEditBox.Text;
|
get => CodeEditBox.Text;
|
||||||
set => CodeEditBox.Text = value;
|
set => CodeEditBox.Text = value;
|
||||||
}
|
}
|
||||||
|
public Action? onSaveCmd;
|
||||||
public BaseEditor()
|
public BaseEditor()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -24,6 +29,31 @@ public partial class BaseEditor : UserControl
|
|||||||
_textMateInstallation = _textEditor.InstallTextMate(_registryOptions);
|
_textMateInstallation = _textEditor.InstallTextMate(_registryOptions);
|
||||||
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(".js").Id));
|
_textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(_registryOptions.GetLanguageByExtension(".js").Id));
|
||||||
}
|
}
|
||||||
|
var saveBinding = new KeyBinding
|
||||||
|
{
|
||||||
|
Gesture = new KeyGesture(Key.S, KeyModifiers.Control),
|
||||||
|
Command = new saveCmd() { onSave = Save }
|
||||||
|
};
|
||||||
|
|
||||||
|
CodeEditBox.KeyBindings.Add(saveBinding);
|
||||||
|
}
|
||||||
|
void Save()
|
||||||
|
{
|
||||||
|
onSaveCmd?.Invoke();
|
||||||
|
}
|
||||||
|
class saveCmd : ICommand
|
||||||
|
{
|
||||||
|
public event EventHandler? CanExecuteChanged;
|
||||||
|
public Action? onSave;
|
||||||
|
public bool CanExecute(object? parameter)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Execute(object? parameter)
|
||||||
|
{
|
||||||
|
onSave?.Invoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void SetGrammerByExtension(string extension_name)
|
public void SetGrammerByExtension(string extension_name)
|
||||||
{
|
{
|
||||||
@@ -34,4 +64,19 @@ public partial class BaseEditor : UserControl
|
|||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Copy_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
CodeEditBox.Copy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Paste_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
CodeEditBox.Paste();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cut_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
CodeEditBox.Cut();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,12 @@ public partial class FileItem : UserControl
|
|||||||
else
|
else
|
||||||
if (currentItem is IStorageFile file)
|
if (currentItem is IStorageFile file)
|
||||||
{
|
{
|
||||||
|
var btn = EditorProvider.IsOpen(file);
|
||||||
|
if (btn is not null)
|
||||||
|
{
|
||||||
|
EditorProvider.SelectTabPage(btn);
|
||||||
|
}
|
||||||
|
else
|
||||||
if (EditorProvider.TryGetEditor(extension, out var page))
|
if (EditorProvider.TryGetEditor(extension, out var page))
|
||||||
{
|
{
|
||||||
if (page is ITabPage editor)
|
if (page is ITabPage editor)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
|
using Progrart.Pages;
|
||||||
|
|
||||||
namespace Progrart.Controls.TabSystem;
|
namespace Progrart.Controls.TabSystem;
|
||||||
|
|
||||||
@@ -30,6 +32,17 @@ public partial class TabHost : UserControl
|
|||||||
page.BindButton(button);
|
page.BindButton(button);
|
||||||
SelectButton(button);
|
SelectButton(button);
|
||||||
}
|
}
|
||||||
|
public TabButton? IsOpen(IStorageFile file)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach (var item in TabContainer.Children)
|
||||||
|
{
|
||||||
|
if (item is TabButton itemBtn)
|
||||||
|
if (itemBtn.page is IEditorPage page)
|
||||||
|
if (page.IsSameFile(file)) return itemBtn;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
public void SelectButton(TabButton button)
|
public void SelectButton(TabButton button)
|
||||||
{
|
{
|
||||||
foreach (var item in TabContainer.Children)
|
foreach (var item in TabContainer.Children)
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ public partial class EditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsSameFile(IStorageFile file)
|
||||||
|
{
|
||||||
|
return (this.file?.Path == file.Path);
|
||||||
|
}
|
||||||
public void BindButton(TabButton button)
|
public void BindButton(TabButton button)
|
||||||
{
|
{
|
||||||
btn = button;
|
btn = button;
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ namespace Progrart.Pages
|
|||||||
{
|
{
|
||||||
ExtensionMapping[type] = id;
|
ExtensionMapping[type] = id;
|
||||||
}
|
}
|
||||||
|
public static TabButton? IsOpen(IStorageFile file)
|
||||||
|
{
|
||||||
|
return currentHost?.IsOpen(file);
|
||||||
|
}
|
||||||
|
public static void SelectTabPage(TabButton button)
|
||||||
|
{
|
||||||
|
currentHost?.SelectButton(button);
|
||||||
|
}
|
||||||
public static void OpenEditor(ITabPage page)
|
public static void OpenEditor(ITabPage page)
|
||||||
{
|
{
|
||||||
currentHost?.AddPage(page);
|
currentHost?.AddPage(page);
|
||||||
@@ -56,6 +64,7 @@ namespace Progrart.Pages
|
|||||||
{
|
{
|
||||||
void LoadDocument(IStorageFile file);
|
void LoadDocument(IStorageFile file);
|
||||||
void Save();
|
void Save();
|
||||||
|
bool IsSameFile(IStorageFile file);
|
||||||
void Execute(ExecuteArguments? args = null);
|
void Execute(ExecuteArguments? args = null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ namespace Progrart.Pages;
|
|||||||
|
|
||||||
public partial class ImageViewPage : UserControl, ITabPage, IEditorPage
|
public partial class ImageViewPage : UserControl, ITabPage, IEditorPage
|
||||||
{
|
{
|
||||||
|
IStorageFile? file;
|
||||||
public ImageViewPage()
|
public ImageViewPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -31,15 +32,16 @@ public partial class ImageViewPage : UserControl, ITabPage, IEditorPage
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadDocument(IStorageFile file)
|
public void LoadDocument(IStorageFile file)
|
||||||
{
|
{
|
||||||
|
this.file = file;
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
|
||||||
using var fs = await file.OpenReadAsync();
|
using var fs = await file.OpenReadAsync();
|
||||||
Bitmap bitmap = new Bitmap(fs);
|
Bitmap bitmap = new Bitmap(fs);
|
||||||
Dispatcher.UIThread.Invoke(() => {
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
|
{
|
||||||
this.ImageViewer.SetImage(bitmap);
|
this.ImageViewer.SetImage(bitmap);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -52,4 +54,9 @@ public partial class ImageViewPage : UserControl, ITabPage, IEditorPage
|
|||||||
public void SetHost(TabHost host)
|
public void SetHost(TabHost host)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsSameFile(IStorageFile file)
|
||||||
|
{
|
||||||
|
return (this.file?.Path == file.Path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
public ProgrartEditorPage()
|
public ProgrartEditorPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
CodeEditor.onSaveCmd = Save;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BindButton(TabButton button)
|
public void BindButton(TabButton button)
|
||||||
@@ -72,6 +73,11 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsSameFile(IStorageFile file)
|
||||||
|
{
|
||||||
|
return (this.file?.Path==file.Path);
|
||||||
|
}
|
||||||
|
|
||||||
public void LoadDocument(IStorageFile file)
|
public void LoadDocument(IStorageFile file)
|
||||||
{
|
{
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
|||||||
Reference in New Issue
Block a user