@@ -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,45 @@ public ContentForm(UserSettings settings, string baseDocumentationUrl)
130140 dataGridViewManualInstall . Sort ( dataGridViewManualInstall . Columns [ 0 ] , ListSortDirection . Ascending ) ;
131141
132142 ManualInstallBrouwseDir = determineBrowseDir ( ) ;
143+ buttonCancel . Enabled = false ;
144+
145+ setTextBoxesManualInstall ( ) ;
146+ }
147+
148+ void changeManualInstallRoute ( string Route )
149+ {
150+ bool found = false ;
151+
152+ foreach ( var folder in Settings . Folders . Folders )
153+ {
154+ if ( folder . Key == Route )
155+ {
156+ // Route found in folder settings
157+ found = true ;
158+ }
159+ }
160+
161+ if ( found )
162+ {
163+ // search for the next route (1), (2) etc. not found in folder settings
164+ int seqNr = 1 ;
165+ string route = Route + " (" + seqNr + ")" ;
166+ while ( found )
167+ {
168+ found = false ;
169+ foreach ( var folder in Settings . Folders . Folders )
170+ {
171+ if ( folder . Key == route )
172+ {
173+ found = true ;
174+ seqNr ++ ;
175+ route = Route + " (" + seqNr + ")" ;
176+ }
177+ }
178+ }
179+ Settings . Folders . Folders [ route ] = Settings . Folders . Folders [ Route ] ;
180+ Settings . Folders . Folders . Remove ( Route ) ;
181+ }
133182 }
134183
135184 private void tabControlContent_Selecting ( object sender , TabControlCancelEventArgs e )
@@ -138,9 +187,12 @@ private void tabControlContent_Selecting(object sender, TabControlCancelEventArg
138187 {
139188 case "tabPageAutoInstall" :
140189 dataGridViewAutoInstall . Select ( ) ;
190+ buttonCancel . Hide ( ) ;
141191 break ;
142192 case "tabPageManuallyInstall" :
143193 dataGridViewManualInstall . Select ( ) ;
194+ buttonCancel . Show ( ) ;
195+ buttonCancel . Enabled = ManualInstallChangesMade ;
144196 break ;
145197 }
146198 }
@@ -1051,7 +1103,6 @@ private void DisableAutoInstallButtons()
10511103 buttonAutoInstallUpdate . Enabled = false ;
10521104 buttonAutoInstallDelete . Enabled = false ;
10531105 buttonOK . Enabled = false ;
1054- buttonCancel . Enabled = false ;
10551106 }
10561107
10571108 private void setCursorToWaitCursor ( )
@@ -1073,7 +1124,6 @@ private void EnableAutoInstalButtons()
10731124 buttonAutoInstallUpdate . Enabled = route . Installed && ( route . getDownloadType ( ) == ContentRouteSettings . DownloadType . github ) ;
10741125 buttonAutoInstallDelete . Enabled = route . Installed ;
10751126 buttonOK . Enabled = true ;
1076- buttonCancel . Enabled = true ;
10771127
10781128 setCursorToDefaultCursor ( ) ;
10791129 }
@@ -1398,6 +1448,18 @@ private void textBoxManualInstallRoute_TextChanged(object sender, EventArgs e)
13981448 {
13991449 // only update the grid when user is filling/changing the route in the textbox
14001450 dataGridViewManualInstall . CurrentRow . Cells [ 0 ] . Value = textBoxManualInstallRoute . Text ;
1451+ ManualInstallChangesMade = true ;
1452+ buttonCancel . Enabled = true ;
1453+ }
1454+ }
1455+
1456+ private void textBoxManualInstallRoute_Leave ( object sender , EventArgs e )
1457+ {
1458+ string route = textBoxManualInstallRoute . Text . Trim ( ) ;
1459+ textBoxManualInstallRoute . Text = determineUniqueRoute ( route ) ;
1460+ if ( textBoxManualInstallRoute . Text != route )
1461+ {
1462+ dataGridViewManualInstall . CurrentRow . Cells [ 0 ] . Value = textBoxManualInstallRoute . Text ;
14011463 }
14021464 }
14031465
@@ -1452,6 +1514,8 @@ private void buttonManualInstallAdd_Click(object sender, EventArgs e)
14521514 string route = determineUniqueRoute ( Path . GetFileName ( folderBrowser . SelectedPath ) ) ;
14531515 dataGridViewManualInstall . CurrentRow . Cells [ 0 ] . Value = route ;
14541516 dataGridViewManualInstall . CurrentRow . Cells [ 1 ] . Value = folderBrowser . SelectedPath ;
1517+ ManualInstallChangesMade = true ;
1518+ buttonCancel . Enabled = ManualInstallChangesMade ;
14551519 }
14561520 else
14571521 {
@@ -1477,6 +1541,8 @@ private void buttonManualInstallDelete_Click(object sender, EventArgs e)
14771541 if ( dataGridViewManualInstall . CurrentRow != null )
14781542 {
14791543 dataGridViewManualInstall . Rows . Remove ( dataGridViewManualInstall . CurrentRow ) ;
1544+ ManualInstallChangesMade = true ;
1545+ buttonCancel . Enabled = ManualInstallChangesMade ;
14801546 }
14811547 }
14821548
@@ -1499,6 +1565,7 @@ private void setTextBoxesManualInstall()
14991565 }
15001566 else
15011567 {
1568+ // route automatically installed
15021569 textBoxManualInstallRoute . Text = "" ;
15031570 textBoxManualInstallPath . Text = "" ;
15041571 textBoxManualInstallRoute . Enabled = false ;
@@ -1507,25 +1574,47 @@ private void setTextBoxesManualInstall()
15071574 buttonManualInstallDelete . Enabled = false ;
15081575 }
15091576 }
1577+ else
1578+ {
1579+ // empty form, like after installing OR
1580+ textBoxManualInstallRoute . Text = "" ;
1581+ textBoxManualInstallPath . Text = "" ;
1582+ textBoxManualInstallRoute . Enabled = false ;
1583+ textBoxManualInstallPath . Enabled = false ;
1584+ buttonManualInstallBrowse . Enabled = false ;
1585+ buttonManualInstallDelete . Enabled = false ;
1586+ }
15101587 }
15111588
15121589 string determineUniqueRoute ( string Route )
15131590 {
15141591 string route = Route ;
1592+ long seqNr = 0 ;
1593+ bool foundUniqueRoute = false ;
15151594
1516- bool found = false ;
1595+ if ( AutoInstallRoutes . ContainsKey ( route ) )
1596+ {
1597+ // route already exists in the AutoInstall routes
1598+ seqNr = 1 ;
1599+ route = Route + " (" + seqNr + ")" ;
1600+ }
15171601
1518- while ( ! found )
1602+ while ( ! foundUniqueRoute )
15191603 {
1520- found = true ;
1521- for ( int i = 0 ; i < dataGridViewManualInstall . Rows . Count - 1 ; i ++ )
1604+ bool found = false ;
1605+ for ( int i = 0 ; i < dataGridViewManualInstall . Rows . Count ; i ++ )
15221606 {
1523- if ( dataGridViewManualInstall . Rows [ i ] . Cells [ 0 ] . Value . ToString ( ) == route )
1607+ if ( ( ! dataGridViewManualInstall . Rows [ i ] . Selected ) && ( dataGridViewManualInstall . Rows [ i ] . Cells [ 0 ] . Value . ToString ( ) == route ) )
15241608 {
1525- route += " copy" ;
1526- found = false ;
1609+ seqNr ++ ;
1610+ route = Route + " (" + seqNr + ")" ;
1611+ found = true ;
15271612 }
15281613 }
1614+ if ( ! found )
1615+ {
1616+ foundUniqueRoute = true ;
1617+ }
15291618 }
15301619
15311620 return route ;
@@ -1588,6 +1677,21 @@ private static bool isWrongPath(string path, GettextResourceManager catalog)
15881677 return false ;
15891678 }
15901679
1680+ private void buttonCancel_Click ( object sender , EventArgs e )
1681+ {
1682+ string message = Catalog . GetString ( "Cancel: changes made in the 'Manually Installed' tab will not be saved, are you sure?" ) ;
1683+ if ( MessageBox . Show ( message , Catalog . GetString ( "Attention" ) , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) == DialogResult . No )
1684+ {
1685+ // not sure, cancel the cancel
1686+ this . DialogResult = DialogResult . None ;
1687+ }
1688+ else
1689+ {
1690+ // sure to cancel the changes
1691+ ManualInstallChangesMade = false ;
1692+ }
1693+ }
1694+
15911695 private void buttonOK_Click ( object sender , EventArgs e )
15921696 {
15931697 // save "Manually Installed" tab changes into the registry/ini file via Settings.Folders.Folders
@@ -1641,6 +1745,8 @@ private void buttonOK_Click(object sender, EventArgs e)
16411745
16421746 Settings . Save ( ) ;
16431747
1748+ ManualInstallChangesMade = false ;
1749+
16441750 this . Close ( ) ;
16451751 }
16461752
@@ -1672,6 +1778,17 @@ private int findIndexDgvManualInstall(string route)
16721778
16731779 private void DownloadContentForm_FormClosing ( object sender , FormClosingEventArgs formClosingEventArgs )
16741780 {
1781+ if ( ManualInstallChangesMade )
1782+ {
1783+ string message = Catalog . GetString ( "Cancel: changes made in the 'Manually Installed' tab will not be saved, are you sure?" ) ;
1784+ if ( MessageBox . Show ( message , Catalog . GetString ( "Attention" ) , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) == DialogResult . No )
1785+ {
1786+ // not sure, cancel the cancel
1787+ formClosingEventArgs . Cancel = true ;
1788+ return ;
1789+ }
1790+ }
1791+
16751792 if ( AutoInstallClosingBlocked )
16761793 {
16771794 // cancelled event, so continue
0 commit comments