blob: 32c7d7f0463e2bc75155a198e8511f0964a914db (
plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
using System;
using System.Collections.Generic;
using AppKit;
using CoreGraphics;
using System.IO;
using Xamarin.PropertyEditing.Common;
using Foundation;
namespace Xamarin.PropertyEditing.Mac
{
internal class FilePathEditorControl : BasePathEditorControl<FilePath>
{
public FilePathEditorControl (IHostResourceProvider hostResource)
: base (hostResource)
{
this.currentTextField.ToolTip = this.currentTextField.PlaceholderString = string.Format (Properties.Resources.ChooseFileOrDirectory, Properties.Resources.File);
this.panel.CanChooseFiles = true;
this.panel.CanChooseDirectories = false;
this.revealPathButton.ToolTip = string.Format (Properties.Resources.RevealFileOrDirectory, Properties.Resources.File);
this.browsePathButton.ToolTip = string.Format (Properties.Resources.BrowseFileOrDirectory, Properties.Resources.File);
this.panel.Title = string.Format (Properties.Resources.ChooseFileOrDirectory, Properties.Resources.File);
}
protected override void OnRevealPathButtonActivated (object sender, EventArgs e)
{
if (File.Exists (this.currentTextField.StringValue)) {
NSWorkspace.SharedWorkspace.SelectFile (this.currentTextField.StringValue, string.Empty);
}
}
protected override void StoreCurrentValue ()
{
ViewModel.Value = new FilePath (this.currentTextField.StringValue);
}
protected override void UpdateAccessibilityValues ()
{
this.currentTextField.AccessibilityEnabled = this.currentTextField.Enabled;
this.currentTextField.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityPathEditor, ViewModel.Property.Name, Properties.Resources.File);
}
protected override void UpdateValue ()
{
if (ViewModel.Value == null) {
this.revealPathButton.Alignment = NSTextAlignment.Center;
this.currentTextField.StringValue = "";
} else {
this.currentTextField.StringValue = ViewModel.Value.Source ?? string.Empty;
this.revealPathButton.Alignment = NSTextAlignment.Left;
}
SetEnabled ();
}
protected override void SetEnabled ()
{
this.currentTextField.Enabled = ViewModel.Property.CanWrite;
this.browsePathButton.Enabled = ViewModel.Property.CanWrite;
//button states
this.revealPathButton.Enabled = ViewModel.Property.CanWrite && File.Exists (this.currentTextField.StringValue);
Window?.RecalculateKeyViewLoop ();
}
}
}
|