Skip to content

FileAssociations

Summary

Represents the collection of plugin file associations.

Signature

1
public abstract interface FileAssociations

Namespace

cAlgo.API

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 using cAlgo.API;
 using System.IO;
 namespace cAlgo.Plugins;
 [Plugin(AccessRights = AccessRights.None)]
 public class Test : Plugin
 {
     private const string FileSvgIcon = "<svg width='800px' height='800px' viewBox='0 0 1024 1024' class='icon'  version='1.1' xmlns='http://www.w3.org/2000/svg'><path d='M512 960c-92.8 0-160-200-160-448S419.2 64 512 64s160 200 160 448-67.2 448-160 448z m0-32c65.6 0 128-185.6 128-416S577.6 96 512 96s-128 185.6-128 416 62.4 416 128 416z' fill='#050D42' /><path d='M124.8 736c-48-80 92.8-238.4 307.2-363.2S852.8 208 899.2 288 806.4 526.4 592 651.2 171.2 816 124.8 736z m27.2-16c33.6 57.6 225.6 17.6 424-97.6S905.6 361.6 872 304 646.4 286.4 448 401.6 118.4 662.4 152 720z' fill='#050D42' /><path d='M899.2 736c-46.4 80-254.4 38.4-467.2-84.8S76.8 368 124.8 288s254.4-38.4 467.2 84.8S947.2 656 899.2 736z m-27.2-16c33.6-57.6-97.6-203.2-296-318.4S184 246.4 152 304 249.6 507.2 448 622.4s392 155.2 424 97.6z' fill='#050D42' /><path d='M512 592c-44.8 0-80-35.2-80-80s35.2-80 80-80 80 35.2 80 80-35.2 80-80 80zM272 312c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48zM416 880c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z m448-432c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z' fill='#2F4BFF' /></svg>";
     protected override void OnStart()
     {
         var addFileAssociationButton = new Button {Text = "Add File Association for '.test' Extension"};
         addFileAssociationButton.Click += args => 
         {
             FileAssociations.Add(".test", new SvgIcon(FileSvgIcon));
             MessageBox.Show("File Association added for '.test' file extension, create a new file with '.test' extension and open it");
         };
         var removeFileAssociationButton = new Button {Text = "Remove File Association for '.test' Extension"};
         removeFileAssociationButton.Click += args => 
         {
             FileAssociations.Remove(".test");
         };
         var panel = new StackPanel {Orientation = Orientation.Vertical};
         panel.AddChild(addFileAssociationButton);
         panel.AddChild(removeFileAssociationButton);
         var aspBlock = Asp.SymbolTab.AddBlock("File Association Test");
         aspBlock.Child = panel;
         // Whenever a file that has association is opened
         // this event will be triggered and you can use
         // args to get the file path and read it.
         FileAssociations.FileOpened += args => 
         {
             Print($"File {args.FilePath} opened, Size: {new FileInfo(args.FilePath).Length}");
         };
     }
 }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 import clr
 clr.AddReference("cAlgo.API")
 from cAlgo.API import *
 from System.IO import FileInfo
 class Test():
     FileSvgIcon = "<svg width='800px' height='800px' viewBox='0 0 1024 1024' class='icon'  version='1.1' xmlns='http://www.w3.org/2000/svg'><path d='M512 960c-92.8 0-160-200-160-448S419.2 64 512 64s160 200 160 448-67.2 448-160 448z m0-32c65.6 0 128-185.6 128-416S577.6 96 512 96s-128 185.6-128 416 62.4 416 128 416z' fill='#050D42' /><path d='M124.8 736c-48-80 92.8-238.4 307.2-363.2S852.8 208 899.2 288 806.4 526.4 592 651.2 171.2 816 124.8 736z m27.2-16c33.6 57.6 225.6 17.6 424-97.6S905.6 361.6 872 304 646.4 286.4 448 401.6 118.4 662.4 152 720z' fill='#050D42' /><path d='M899.2 736c-46.4 80-254.4 38.4-467.2-84.8S76.8 368 124.8 288s254.4-38.4 467.2 84.8S947.2 656 899.2 736z m-27.2-16c33.6-57.6-97.6-203.2-296-318.4S184 246.4 152 304 249.6 507.2 448 622.4s392 155.2 424 97.6z' fill='#050D42' /><path d='M512 592c-44.8 0-80-35.2-80-80s35.2-80 80-80 80 35.2 80 80-35.2 80-80 80zM272 312c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48zM416 880c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z m448-432c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z' fill='#2F4BFF' /></svg>"
     def on_start(self):
         addFileAssociationButton = Button()
         addFileAssociationButton.Text = "Add File Association for '.test' Extension"
         addFileAssociationButton.Click += self.on_add_file_association_button_click
         removeFileAssociationButton = Button()
         removeFileAssociationButton.Text = "Remove File Association for '.test' Extension"
         removeFileAssociationButton.Click += lambda _: api.FileAssociations.Remove(".test")
         panel = StackPanel()
         panel.Orientation = Orientation.Vertical
         panel.AddChild(addFileAssociationButton)
         panel.AddChild(removeFileAssociationButton)
         aspBlock = api.Asp.SymbolTab.AddBlock("File Association Test")
         aspBlock.Child = panel
         # Whenever a file that has association is opened
         # this event will be triggered and you can use
         # args to get the file path and read it.
         api.FileAssociations.FileOpened += lambda args: print(f"File {args.FilePath} opened, Size: {FileInfo(args.FilePath).Length}")
     def on_add_file_association_button_click(self, args):
         api.FileAssociations.Add(".test", SvgIcon(self.FileSvgIcon))
         MessageBox.Show("File Association added for '.test' file extension, create a new file with '.test' extension and open it")

Methods

Add (3)

Add (1 of 3)

Summary

Adds a file extension to the list of associations along with a specified icon file path.

Remarks

These file extensions aren't allowed: exe, dll, bat, cmd, msi, ps1, com, sys, inf, ini, iso, img, vmdk, vdi, ova, app, dmg, pkg, command, sh, bin, iso, xcappdata

Signature

1
public abstract void Add(string fileExtension, string iconFilePath)

Parameters

Name Type Description
fileExtension string File extension with dot, ex: .pdf
iconFilePath string Icon file path

Return Value

void

Add (2 of 3)

Summary

Adds a file extension to the list of associations along with a specified icon file path.

Remarks

These file extensions aren't allowed: exe, dll, bat, cmd, msi, ps1, com, sys, inf, ini, iso, img, vmdk, vdi, ova, app, dmg, pkg, command, sh, bin, iso, xcappdata

Signature

1
public abstract void Add(string fileExtension, SvgIcon svgIcon)

Parameters

Name Type Description
fileExtension string File extension with dot, ex: .pdf
svgIcon SvgIcon SVG Icon

Return Value

void

Add (3 of 3)

Summary

Adds a file extension to the list of associations without specifying an icon.

Remarks

These file extensions aren't allowed: exe, dll, bat, cmd, msi, ps1, com, sys, inf, ini, iso, img, vmdk, vdi, ova, app, dmg, pkg, command, sh, bin, iso, xcappdata

Signature

1
public abstract void Add(string fileExtension)

Parameters

Name Type Description
fileExtension string File extension with dot, ex: .pdf

Return Value

void

Contains

Summary

Checks if the specified file extension is already associated.

Signature

1
public abstract bool Contains(string fileExtension)

Parameters

Name Type Description
fileExtension string File extension with dot, ex: .pdf

Return Value

bool

Remove

Summary

Removes a file extension from the list of associations.

Signature

1
public abstract void Remove(string fileExtension)

Parameters

Name Type Description
fileExtension string File extension with dot, ex: .pdf

Return Value

void

Events

FileOpened

Summary

Event triggered when a file associated with a registered extension is opened.

Signature

1
public abstract event Action<FileAssociationsFileOpenedEventArgs> FileOpened;