Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
diaskhanimanberdiyev committed Sep 28, 2024
1 parent 3c11fe6 commit 9cac95c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
2 changes: 2 additions & 0 deletions src/SmartCommander/Plugins/ListerPluginWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Runtime.InteropServices;

namespace SmartCommander.Plugins;

public class ListerPluginWrapper : IDisposable
{
private IntPtr _pluginHandle;
Expand Down
28 changes: 14 additions & 14 deletions src/SmartCommander/Plugins/PluginManager.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using System;

namespace SmartCommander.TcPlugins
namespace SmartCommander.Plugins;

public static class PluginManager
{
public static class PluginManager
public static ListerPluginWrapper CreateListerWrapper()
{
public static ListerPluginWrapper CreateListerWrapper()
{
//string pluginPath = "C:\\totalcmd\\plugins\\CodeViewer\\CodeViewer.wlx64";
string pluginPath = "C:\\totalcmd\\plugins\\wlx\\CodeViewer\\CodeViewer.wlx64";
return new ListerPluginWrapper(pluginPath);
}

public static IntPtr CreateListerWindow(this ListerPluginWrapper listerWrapper,IntPtr parentWindowHandle,string fileToLoad)
{
int showFlags = 1;
return listerWrapper.LoadFile(parentWindowHandle, fileToLoad, showFlags);
}
//string pluginPath = "C:\\totalcmd\\plugins\\CodeViewer\\CodeViewer.wlx64";
string pluginPath = "C:\\totalcmd\\plugins\\wlx\\CodeViewer\\CodeViewer.wlx64";
return new ListerPluginWrapper(pluginPath);
}

public static IntPtr CreateListerWindow(this ListerPluginWrapper listerWrapper, IntPtr parentWindowHandle, string fileToLoad)
{
int showFlags = 1;
return listerWrapper.LoadFile(parentWindowHandle, fileToLoad, showFlags);
}

}

33 changes: 9 additions & 24 deletions src/SmartCommander/Views/ViewerWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using Avalonia.Controls;
using Avalonia.Controls.Platform;
using Avalonia.Platform;
using AvaloniaEdit.Editing;
using SmartCommander.TcPlugins;
using SmartCommander.Plugins;
using SmartCommander.ViewModels;
using System;
using System.Resources;

namespace SmartCommander;

public partial class ViewerWindow : Window
{
ListerPluginWrapper listerPluginWrapper { get; set; }
IntPtr listerWindowHandle { get; set; }
public ViewerWindow()
{
Expand All @@ -28,13 +25,14 @@ private void OnWindowOpened(object? sender, EventArgs e)
{
var viewModel = this.DataContext as ViewerViewModel;


var embed = new EmbedSample(viewModel!.Filename);
if (embed.CanShowByPlugin)
if (OperatingSystem.IsWindows())
{
grid.Children.Add(embed);
var embed = new EmbedSample(viewModel!.Filename);
if (embed.CanShowByPlugin)
{
grid.Children.Add(embed);
}
}

}

}
Expand All @@ -48,18 +46,14 @@ public Win32WindowControlHandle(IntPtr handle, string descriptor) : base(handle,

public void Destroy()
{
///_ = WinApi.DestroyWindow(Handle);
}
}

public class EmbedSample : NativeControlHost
{
//public static INativeDemoControl? Implementation { get; set; }
ListerPluginWrapper listerPluginWrapper { get; set; }
IntPtr listerWindowHandle { get; set; }

string filename;

public bool CanShowByPlugin
{
get
Expand All @@ -72,14 +66,14 @@ public EmbedSample(string Filename)
{
HorizontalAlignment = 0;
VerticalAlignment = 0;
filename = Filename;
listerPluginWrapper = PluginManager.CreateListerWrapper();
listerWindowHandle = listerPluginWrapper.CreateListerWindow(IntPtr.Zero, filename);
listerWindowHandle = listerPluginWrapper.CreateListerWindow(IntPtr.Zero, Filename);
}


protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
{
//TODO better use INativeDemoControl? Implementation; to make it cross platform
return new Win32WindowControlHandle(listerWindowHandle, "Lister");
}

Expand All @@ -89,12 +83,3 @@ protected override void DestroyNativeControlCore(IPlatformHandle control)
base.DestroyNativeControlCore(control);
}
}

//public interface INativeDemoControl
//{
// /// <param name="isSecond">Used to specify which control should be displayed as a demo</param>
// /// <param name="parent"></param>
// /// <param name="createDefault"></param>
// IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault);
//}

0 comments on commit 9cac95c

Please sign in to comment.