Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Copy images on copy / add minimize_to_tray option #787

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions OpenRPA.Interfaces/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Config
public bool use_animate_mouse { get { return GetProperty(null, false); } set { SetProperty(null, value); } }
public TimeSpan use_postwait { get { return GetProperty(null, TimeSpan.Zero); } set { SetProperty(null, value); } }
public bool minimize { get { return GetProperty(null, true); } set { SetProperty(null, value); } }
public bool minimize_to_tray { get { return GetProperty(null, true); } set { SetProperty(null, value); } }
public bool recording_add_to_designer { get { return GetProperty(null, true); } set { SetProperty(null, value); } }
public TimeSpan reloadinterval { get { return GetProperty(null, TimeSpan.FromMinutes(5)); } set { SetProperty(null, value); } }
public TimeSpan move_animation_run_time { get { return GetProperty(null, TimeSpan.FromMilliseconds(500)); } set { SetProperty(null, value); } }
Expand Down Expand Up @@ -237,6 +238,7 @@ public void Save(string filename)
_ = use_animate_mouse;
_ = use_postwait;
_ = minimize;
_ = minimize_to_tray;
_ = recording_add_to_designer;
_ = reloadinterval;
_ = move_animation_run_time;
Expand Down
24 changes: 24 additions & 0 deletions OpenRPA.Interfaces/Image/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,29 @@ public static async Task<Bitmap> LoadBitmap(string basepath, string ImageString)
}
return b;
}
public static async Task<string> LoadImages(string xaml)
{
var doc = new System.Xml.XmlDocument(); bool foundone = false;
doc.LoadXml(xaml);
var nodes = doc.SelectNodes("//*[@Image]");
foreach (System.Xml.XmlNode n in nodes)
{
var image = n.Attributes["Image"].Value;
Console.WriteLine("Image: " + image);
if (System.Text.RegularExpressions.Regex.Match(image, "[a-f0-9]{24}").Success)
{
Log.Debug("Loading image id " + image);
using (var b = await Interfaces.Image.Util.LoadBitmap(image))
{
image = Interfaces.Image.Util.Bitmap2Base64(b);
}
foundone = true;
n.Attributes["Image"].Value = image;
}
}
if (foundone) return doc.OuterXml;
return xaml;
}

}
}
2 changes: 1 addition & 1 deletion OpenRPA.Script/OpenRPA.Script.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.1.3.50" />
<PackageReference Include="Python.Included" Version="3.11.4" />
<PackageReference Include="Python.Included" Version="3.7.3.13" />
<PackageReference Include="sharpAHK" Version="1.0.0.5" />
<PackageReference Include="System.Management.Automation.dll" Version="10.0.10586" />
</ItemGroup>
Expand Down
48 changes: 39 additions & 9 deletions OpenRPA/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ private void Window_Closed(object sender, EventArgs e)
private void Window_StateChanged(object sender, EventArgs e)
{
Log.FunctionIndent("MainWindow", "Window_StateChanged");
if (!Config.local.minimize_to_tray) return;
if (WindowState == WindowState.Minimized)
{
Visibility = Visibility.Hidden;
Expand Down Expand Up @@ -2469,7 +2470,16 @@ internal bool CanCopy(object _item)
{
try
{
return (SelectedContent is Views.WFDesigner);
if (SelectedContent is Views.WFDesigner) return true;
if (SelectedContent is Views.OpenProject view)
{
var val = view.listWorkflows.SelectedValue;
if (val is Workflow wf)
{
return true;
}
}
return false;
}
catch (Exception ex)
{
Expand All @@ -2482,14 +2492,34 @@ internal async void OnCopy(object _item)
Log.FunctionIndent("MainWindow", "OnCopy");
try
{
var designer = (Views.WFDesigner)SelectedContent;
await designer.SaveAsync();
Workflow workflow = await Workflow.Create(designer.Workflow.Project(), "Copy of " + designer.Workflow.name);
var xaml = designer.Workflow.Xaml;
xaml = Views.WFDesigner.SetWorkflowName(xaml, workflow.name);
workflow.Xaml = xaml;
workflow.name = "Copy of " + designer.Workflow.name;
_onOpenWorkflow(workflow, true);
string xaml = "";
Workflow workflow = null;
if (SelectedContent is Views.WFDesigner)
{
var designer = (Views.WFDesigner)SelectedContent;
await designer.SaveAsync();
xaml = designer.Workflow.Xaml;
workflow = await Workflow.Create(designer.Workflow.Project(), "Copy of " + designer.Workflow.name);
workflow.name = "Copy of " + designer.Workflow.name;
xaml = await Interfaces.Image.Util.LoadImages(xaml);
xaml = Views.WFDesigner.SetWorkflowName(xaml, workflow.name);
workflow.Xaml = xaml;
_onOpenWorkflow(workflow, true);
}
if (SelectedContent is Views.OpenProject view)
{
var val = view.listWorkflows.SelectedValue;
if (val is Workflow wf)
{
xaml = wf.Xaml;
workflow = await Workflow.Create(wf.Project(), "Copy of " + wf.name);
workflow.name = "Copy of " + wf.name;
xaml = await Interfaces.Image.Util.LoadImages(xaml);
xaml = Views.WFDesigner.SetWorkflowName(xaml, workflow.name);
workflow.Xaml = xaml;
await workflow.Save();
}
}
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenRPA/OpenRPA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Description>Base UI of OpenRPA, used as part of OpenRPA robot</Description>
<PackageLicenseExpression>MPL-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/open-rpa/openrpa</PackageProjectUrl>
<Version>1.4.57.5</Version>
<Version>1.4.57.6</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>openrpa.png</PackageIcon>
<Configurations>Debug;Release;ReleaseNuget;PrepInstaller</Configurations>
Expand Down
1 change: 1 addition & 0 deletions OpenRPA/Views/OpenProject.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<MenuItem Header="{x:Static or:strings.copyrelativefilename}" Command="{Binding Data.CopyRelativeFilenameCommand, Source={StaticResource proxy}}" CommandParameter="{Binding}" />
<MenuItem Header="{x:Static or:strings.delete}" Command="{Binding Data.DeleteCommand, Source={StaticResource proxy}}" CommandParameter="{Binding}" />
<MenuItem Header="{x:Static or:strings.menu_get_server_version}" Command="{Binding Data.GetServerVersionCommand, Source={StaticResource proxy}}" CommandParameter="{Binding}" />
<MenuItem Header="{x:Static or:strings.copy}" Command="{Binding Data.CopyCommand, Source={StaticResource proxy}}" CommandParameter="{Binding}" />
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
Expand Down
9 changes: 9 additions & 0 deletions OpenRPA/Views/OpenProject.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public ICommand GetServerVersionCommand
return new RelayCommand<object>(OnGetServerVersion, CanGetServerVersion);
}
}
public ICommand CopyCommand
{
get
{
if (RobotInstance.instance.Window is MainWindow main) return new RelayCommand<object>(main.OnCopy, main.CanCopy);
return null;
}
}

public ICommand SerializableCommand
{
get
Expand Down