@@ -47,7 +47,7 @@ public string SelectedName
47
47
}
48
48
}
49
49
50
- private bool IsEdit { get ; set ; }
50
+ private bool IsEdit { get ; }
51
51
private AccessLink SelectedAccessLink { get ; }
52
52
53
53
public ObservableCollection < AccessLink > QuickAccessLinks { get ; }
@@ -77,30 +77,55 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
77
77
78
78
private void OnDoneButtonClick ( object sender , RoutedEventArgs e )
79
79
{
80
+ // Validate the input before proceeding
80
81
if ( string . IsNullOrEmpty ( SelectedName ) || string . IsNullOrEmpty ( SelectedPath ) )
81
82
{
82
83
var warning = Main . Context . API . GetTranslation ( "plugin_explorer_quick_access_link_no_folder_selected" ) ;
83
84
Main . Context . API . ShowMsgBox ( warning ) ;
84
85
return ;
85
86
}
86
-
87
+
88
+ // Check if the path already exists in the quick access links
87
89
if ( QuickAccessLinks . Any ( x =>
88
90
x . Path . Equals ( SelectedPath , StringComparison . OrdinalIgnoreCase ) &&
89
- x . Name . Equals ( SelectedName , StringComparison . OrdinalIgnoreCase ) ) )
91
+ x . Name . Equals ( SelectedName , StringComparison . OrdinalIgnoreCase ) ) )
90
92
{
91
93
var warning = Main . Context . API . GetTranslation ( "plugin_explorer_quick_access_link_path_already_exists" ) ;
92
94
Main . Context . API . ShowMsgBox ( warning ) ;
93
95
return ;
94
96
}
97
+
98
+ // If editing, update the existing link
95
99
if ( IsEdit )
96
100
{
97
- EditAccessLink ( ) ;
98
- return ;
101
+ if ( SelectedAccessLink == null ) return ;
102
+
103
+ var index = QuickAccessLinks . IndexOf ( SelectedAccessLink ) ;
104
+ if ( index >= 0 )
105
+ {
106
+ var updatedLink = new AccessLink
107
+ {
108
+ Name = SelectedName ,
109
+ Type = SelectedAccessLink . Type ,
110
+ Path = SelectedPath
111
+ } ;
112
+ QuickAccessLinks [ index ] = updatedLink ;
113
+ }
114
+ DialogResult = true ;
115
+ Close ( ) ;
116
+ }
117
+ // Otherwise, add a new one
118
+ else
119
+ {
120
+ var newAccessLink = new AccessLink
121
+ {
122
+ Name = SelectedName ,
123
+ Path = SelectedPath
124
+ } ;
125
+ QuickAccessLinks . Add ( newAccessLink ) ;
126
+ DialogResult = true ;
127
+ Close ( ) ;
99
128
}
100
- var newAccessLink = new AccessLink { Name = SelectedName , Path = SelectedPath } ;
101
- QuickAccessLinks . Add ( newAccessLink ) ;
102
- DialogResult = true ;
103
- Close ( ) ;
104
129
}
105
130
106
131
private void SelectPath_OnClick ( object commandParameter , RoutedEventArgs e )
@@ -112,21 +137,6 @@ private void SelectPath_OnClick(object commandParameter, RoutedEventArgs e)
112
137
113
138
SelectedPath = folderBrowserDialog . SelectedPath ;
114
139
}
115
-
116
- private void EditAccessLink ( )
117
- {
118
- if ( SelectedAccessLink == null ) return ;
119
-
120
- var index = QuickAccessLinks . IndexOf ( SelectedAccessLink ) ;
121
- if ( index >= 0 )
122
- {
123
- var updatedLink = new AccessLink { Name = SelectedName , Path = SelectedPath } ;
124
- QuickAccessLinks [ index ] = updatedLink ;
125
- }
126
- DialogResult = true ;
127
- IsEdit = false ;
128
- Close ( ) ;
129
- }
130
140
131
141
public event PropertyChangedEventHandler PropertyChanged ;
132
142
0 commit comments