@@ -61,6 +61,8 @@ public partial class ContentForm : Form
6161 private bool In_dataGridViewManualInstall_SelectionChanged = false ;
6262 private bool In_buttonManualInstallAdd_Click = false ;
6363
64+ private bool ManualInstallChangesMade = false ;
65+
6466 public ContentForm ( UserSettings settings , string baseDocumentationUrl )
6567 {
6668 InitializeComponent ( ) ;
@@ -93,6 +95,10 @@ public ContentForm(UserSettings settings, string baseDocumentationUrl)
9395 route . Installed ? route . DateInstalled . ToString ( CultureInfo . CurrentCulture . DateTimeFormat ) : "" ,
9496 route . Url } ) ;
9597 dataGridViewAutoInstall . Rows [ indexAdded ] . Cells [ 2 ] . ToolTipText = route . Url ;
98+ if ( ! route . Installed )
99+ {
100+ changeManualInstallRoute ( routeName ) ;
101+ }
96102 }
97103
98104 dataGridViewAutoInstall . Sort ( dataGridViewAutoInstall . Columns [ 0 ] , ListSortDirection . Ascending ) ;
@@ -113,6 +119,10 @@ public ContentForm(UserSettings settings, string baseDocumentationUrl)
113119 // set focus to datagridview so that arrow keys can be used to scroll thru the list
114120 dataGridViewAutoInstall . Select ( ) ;
115121
122+ // tab "Auto Installed" does not contain a Cancel button
123+ // it's too difficult and not logical to rollback an "Auto Installed" route
124+ buttonCancel . Hide ( ) ;
125+
116126 //
117127 // "Manually Installed" tab
118128 //
@@ -130,6 +140,43 @@ public ContentForm(UserSettings settings, string baseDocumentationUrl)
130140 dataGridViewManualInstall . Sort ( dataGridViewManualInstall . Columns [ 0 ] , ListSortDirection . Ascending ) ;
131141
132142 ManualInstallBrouwseDir = determineBrowseDir ( ) ;
143+ buttonCancel . Enabled = false ;
144+ }
145+
146+ void changeManualInstallRoute ( string Route )
147+ {
148+ bool found = false ;
149+
150+ foreach ( var folder in Settings . Folders . Folders )
151+ {
152+ if ( folder . Key == Route )
153+ {
154+ // Route found in folder settings
155+ found = true ;
156+ }
157+ }
158+
159+ if ( found )
160+ {
161+ // search for the next route (1), (2) etc. not found in folder settings
162+ int seqNr = 1 ;
163+ string route = Route + " (" + seqNr + ")" ;
164+ while ( found )
165+ {
166+ found = false ;
167+ foreach ( var folder in Settings . Folders . Folders )
168+ {
169+ if ( folder . Key == route )
170+ {
171+ found = true ;
172+ seqNr ++ ;
173+ route = Route + " (" + seqNr + ")" ;
174+ }
175+ }
176+ }
177+ Settings . Folders . Folders [ route ] = Settings . Folders . Folders [ Route ] ;
178+ Settings . Folders . Folders . Remove ( Route ) ;
179+ }
133180 }
134181
135182 private void tabControlContent_Selecting ( object sender , TabControlCancelEventArgs e )
@@ -138,9 +185,12 @@ private void tabControlContent_Selecting(object sender, TabControlCancelEventArg
138185 {
139186 case "tabPageAutoInstall" :
140187 dataGridViewAutoInstall . Select ( ) ;
188+ buttonCancel . Hide ( ) ;
141189 break ;
142190 case "tabPageManuallyInstall" :
143191 dataGridViewManualInstall . Select ( ) ;
192+ buttonCancel . Show ( ) ;
193+ buttonCancel . Enabled = ManualInstallChangesMade ;
144194 break ;
145195 }
146196 }
@@ -1051,7 +1101,6 @@ private void DisableAutoInstallButtons()
10511101 buttonAutoInstallUpdate . Enabled = false ;
10521102 buttonAutoInstallDelete . Enabled = false ;
10531103 buttonOK . Enabled = false ;
1054- buttonCancel . Enabled = false ;
10551104 }
10561105
10571106 private void setCursorToWaitCursor ( )
@@ -1073,7 +1122,6 @@ private void EnableAutoInstalButtons()
10731122 buttonAutoInstallUpdate . Enabled = route . Installed && ( route . getDownloadType ( ) == ContentRouteSettings . DownloadType . github ) ;
10741123 buttonAutoInstallDelete . Enabled = route . Installed ;
10751124 buttonOK . Enabled = true ;
1076- buttonCancel . Enabled = true ;
10771125
10781126 setCursorToDefaultCursor ( ) ;
10791127 }
@@ -1398,6 +1446,18 @@ private void textBoxManualInstallRoute_TextChanged(object sender, EventArgs e)
13981446 {
13991447 // only update the grid when user is filling/changing the route in the textbox
14001448 dataGridViewManualInstall . CurrentRow . Cells [ 0 ] . Value = textBoxManualInstallRoute . Text ;
1449+ ManualInstallChangesMade = true ;
1450+ buttonCancel . Enabled = true ;
1451+ }
1452+ }
1453+
1454+ private void textBoxManualInstallRoute_Leave ( object sender , EventArgs e )
1455+ {
1456+ string route = textBoxManualInstallRoute . Text ;
1457+ textBoxManualInstallRoute . Text = determineUniqueRoute ( route ) ;
1458+ if ( textBoxManualInstallRoute . Text != route )
1459+ {
1460+ dataGridViewManualInstall . CurrentRow . Cells [ 0 ] . Value = textBoxManualInstallRoute . Text ;
14011461 }
14021462 }
14031463
@@ -1452,6 +1512,8 @@ private void buttonManualInstallAdd_Click(object sender, EventArgs e)
14521512 string route = determineUniqueRoute ( Path . GetFileName ( folderBrowser . SelectedPath ) ) ;
14531513 dataGridViewManualInstall . CurrentRow . Cells [ 0 ] . Value = route ;
14541514 dataGridViewManualInstall . CurrentRow . Cells [ 1 ] . Value = folderBrowser . SelectedPath ;
1515+ ManualInstallChangesMade = true ;
1516+ buttonCancel . Enabled = ManualInstallChangesMade ;
14551517 }
14561518 else
14571519 {
@@ -1477,6 +1539,8 @@ private void buttonManualInstallDelete_Click(object sender, EventArgs e)
14771539 if ( dataGridViewManualInstall . CurrentRow != null )
14781540 {
14791541 dataGridViewManualInstall . Rows . Remove ( dataGridViewManualInstall . CurrentRow ) ;
1542+ ManualInstallChangesMade = true ;
1543+ buttonCancel . Enabled = ManualInstallChangesMade ;
14801544 }
14811545 }
14821546
@@ -1512,17 +1576,18 @@ private void setTextBoxesManualInstall()
15121576 string determineUniqueRoute ( string Route )
15131577 {
15141578 string route = Route ;
1515-
1579+ long seqNr = 0 ;
15161580 bool found = false ;
15171581
15181582 while ( ! found )
15191583 {
15201584 found = true ;
15211585 for ( int i = 0 ; i < dataGridViewManualInstall . Rows . Count - 1 ; i ++ )
15221586 {
1523- if ( dataGridViewManualInstall . Rows [ i ] . Cells [ 0 ] . Value . ToString ( ) == route )
1524- {
1525- route += " copy" ;
1587+ if ( ( ( dataGridViewManualInstall . Rows [ i ] . Cells [ 0 ] . Value . ToString ( ) == route ) && ( ! dataGridViewManualInstall . Rows [ i ] . Selected ) ) ||
1588+ ( AutoInstallRoutes . ContainsKey ( route ) ) ) {
1589+ seqNr ++ ;
1590+ route = Route + " (" + seqNr + ")" ;
15261591 found = false ;
15271592 }
15281593 }
@@ -1588,6 +1653,21 @@ private static bool isWrongPath(string path, GettextResourceManager catalog)
15881653 return false ;
15891654 }
15901655
1656+ private void buttonCancel_Click ( object sender , EventArgs e )
1657+ {
1658+ string message = Catalog . GetString ( "Cancel: changes made in the 'Manually Installed' tab will not be saved, are you sure?" ) ;
1659+ if ( MessageBox . Show ( message , Catalog . GetString ( "Attention" ) , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) == DialogResult . No )
1660+ {
1661+ // not sure, cancel the cancel
1662+ this . DialogResult = DialogResult . None ;
1663+ }
1664+ else
1665+ {
1666+ // sure to cancel the changes
1667+ ManualInstallChangesMade = false ;
1668+ }
1669+ }
1670+
15911671 private void buttonOK_Click ( object sender , EventArgs e )
15921672 {
15931673 // save "Manually Installed" tab changes into the registry/ini file via Settings.Folders.Folders
@@ -1641,6 +1721,8 @@ private void buttonOK_Click(object sender, EventArgs e)
16411721
16421722 Settings . Save ( ) ;
16431723
1724+ ManualInstallChangesMade = false ;
1725+
16441726 this . Close ( ) ;
16451727 }
16461728
@@ -1672,6 +1754,17 @@ private int findIndexDgvManualInstall(string route)
16721754
16731755 private void DownloadContentForm_FormClosing ( object sender , FormClosingEventArgs formClosingEventArgs )
16741756 {
1757+ if ( ManualInstallChangesMade )
1758+ {
1759+ string message = Catalog . GetString ( "Cancel: changes made in the 'Manually Installed' tab will not be saved, are you sure?" ) ;
1760+ if ( MessageBox . Show ( message , Catalog . GetString ( "Attention" ) , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) == DialogResult . No )
1761+ {
1762+ // not sure, cancel the cancel
1763+ formClosingEventArgs . Cancel = true ;
1764+ return ;
1765+ }
1766+ }
1767+
16751768 if ( AutoInstallClosingBlocked )
16761769 {
16771770 // cancelled event, so continue
0 commit comments