Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up window disabling #3642

Merged
merged 1 commit into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GUI/Controls/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void Reset(bool cancelable)
});
}

public void Finish(bool success)
public void Finish()
{
OnCancel = null;
Util.Invoke(this, () =>
Expand Down
37 changes: 30 additions & 7 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,6 @@ private void installFromckanToolStripMenuItem_Click(object sender, EventArgs e)
continue;
}

menuStrip1.Enabled = false;

InstallModuleDriver(registry_manager.registry, module);
}
registry_manager.Save(true);
Expand Down Expand Up @@ -815,18 +813,43 @@ private void ManageMods_OnRefresh(Dictionary<string, bool> oldModules = null)
{
tabController.RenameTab("WaitTabPage", Properties.Resources.MainModListWaitTitle);
ShowWaitDialog();
Util.Invoke(this, SwitchEnabledState);
tabController.SetTabLock(true);
DisableMainWindow();
Wait.StartWaiting(
ManageMods.Update,
(sender, e) => {
HideWaitDialog(true);
tabController.SetTabLock(false);
Util.Invoke(this, SwitchEnabledState);
HideWaitDialog();
EnableMainWindow();
SetupDefaultSearch();
},
false,
oldModules);
}

private void EnableMainWindow()
{
Util.Invoke(this, () =>
{
Enabled = true;
menuStrip1.Enabled = true;
tabController.SetTabLock(false);
/* Windows (7 & 8 only?) bug #1548 has extra facets.
* parent.childcontrol.Enabled = false seems to disable the parent,
* if childcontrol had focus. Depending on optimization steps,
* parent.childcontrol.Enabled = true does not necessarily
* re-enable the parent.*/
this.Focus();
});
}

private void DisableMainWindow()
{
Util.Invoke(this, () =>
{
Enabled = false;
menuStrip1.Enabled = false;
tabController.SetTabLock(true);
});
}

}
}
4 changes: 2 additions & 2 deletions GUI/Main/MainAutoUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void UpdateCKAN()
{
ResetProgress();
ShowWaitDialog();
SwitchEnabledState();
DisableMainWindow();
tabController.RenameTab("WaitTabPage", Properties.Resources.MainUpgradingWaitTitle);
Wait.SetDescription(string.Format(Properties.Resources.MainUpgradingTo, AutoUpdate.Instance.latestUpdate.Version));

Expand All @@ -70,7 +70,7 @@ public void UpdateCKAN()
private void UpdateReady(object sender, RunWorkerCompletedEventArgs e)
{
// Close will be cancelled if the window is still disabled
SwitchEnabledState();
EnableMainWindow();
Close();
}

Expand Down
2 changes: 1 addition & 1 deletion GUI/Main/MainChangeset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void Changeset_OnCancelChanges(bool reset)

private void Changeset_OnConfirmChanges()
{
menuStrip1.Enabled = false;
DisableMainWindow();

// Using the changeset passed in can cause issues with versions.
// An example is Mechjeb for FAR at 25/06/2015 with a 1.0.2 install.
Expand Down
6 changes: 2 additions & 4 deletions GUI/Main/MainDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ public void PostModCaching(object sender, RunWorkerCompletedEventArgs e)

case CancelledActionKraken exc:
// User already knows they cancelled, get out
HideWaitDialog(false);
tabController.SetTabLock(false);
Util.Invoke(this, () => Enabled = true);
Util.Invoke(menuStrip1, () => menuStrip1.Enabled = true);
HideWaitDialog();
EnableMainWindow();
break;

default:
Expand Down
6 changes: 2 additions & 4 deletions GUI/Main/MainExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ private void exportModPackToolStripMenuItem_Click(object sender, EventArgs e)
Task.Factory.StartNew(() =>
{
AddStatusMessage("");
Util.Invoke(this, () => menuStrip1.Enabled = false);
tabController.ShowTab("EditModpackTabPage", 2);
tabController.SetTabLock(true);
DisableMainWindow();
var mgr = RegistryManager.Instance(CurrentInstance);
EditModpack.LoadModule(mgr.GenerateModpack(false, true), mgr.registry);
// This will block till the user is done
EditModpack.Wait(currentUser);
tabController.ShowTab("ManageModsTabPage");
tabController.HideTab("EditModpackTabPage");
tabController.SetTabLock(false);
Util.Invoke(this, () => menuStrip1.Enabled = true);
EnableMainWindow();
});
}

Expand Down
8 changes: 4 additions & 4 deletions GUI/Main/MainImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ private void ImportModules()
{
// Show WaitTabPage (status page) and lock it.
tabController.RenameTab("WaitTabPage", Properties.Resources.MainImportWaitTitle);
tabController.ShowTab("WaitTabPage");
tabController.SetTabLock(true);
ShowWaitDialog();
DisableMainWindow();

try
{
Expand All @@ -46,8 +46,8 @@ private void ImportModules()
finally
{
// Put GUI back the way we found it
tabController.SetTabLock(false);
tabController.HideTab("WaitTabPage");
EnableMainWindow();
HideWaitDialog();
}
}
}
Expand Down
19 changes: 6 additions & 13 deletions GUI/Main/MainInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void InstallModuleDriver(IRegistryQuerier registry, CkanModule module)
{
try
{
DisableMainWindow();
var userChangeSet = new List<ModChange>();
InstalledModule installed = registry.InstalledModule(module.identifier);
if (installed != null)
Expand Down Expand Up @@ -52,8 +53,8 @@ public void InstallModuleDriver(IRegistryQuerier registry, CkanModule module)
catch
{
// If we failed, do the clean-up normally done by PostInstallMods.
HideWaitDialog(false);
menuStrip1.Enabled = true;
HideWaitDialog();
EnableMainWindow();
}
}

Expand Down Expand Up @@ -347,10 +348,8 @@ private void PostInstallMods(object sender, RunWorkerCompletedEventArgs e)

case CancelledActionKraken exc:
// User already knows they cancelled, get out
HideWaitDialog(false);
tabController.SetTabLock(false);
Util.Invoke(this, () => Enabled = true);
Util.Invoke(menuStrip1, () => menuStrip1.Enabled = true);
HideWaitDialog();
EnableMainWindow();
break;

case MissingCertificateKraken exc:
Expand Down Expand Up @@ -412,15 +411,9 @@ private void PostInstallMods(object sender, RunWorkerCompletedEventArgs e)
{
// The Result property throws if InstallMods threw (!!!)
KeyValuePair<bool, ModChanges> result = (KeyValuePair<bool, ModChanges>) e.Result;
AddStatusMessage(Properties.Resources.MainInstallSuccess);
// Rebuilds the list of GUIMods
ManageMods_OnRefresh();

Util.Invoke(this, () => Enabled = true);
Util.Invoke(menuStrip1, () => menuStrip1.Enabled = true);
tabController.SetTabLock(false);

AddStatusMessage(Properties.Resources.MainInstallSuccess);
HideWaitDialog(true);
}
}
}
Expand Down
30 changes: 7 additions & 23 deletions GUI/Main/MainRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,12 @@ public void UpdateRepo()
}
catch { }

Util.Invoke(this, SwitchEnabledState);
DisableMainWindow();

Wait.SetDescription(Properties.Resources.MainRepoContacting);
ShowWaitDialog();
}

private bool _enabled = true;
private void SwitchEnabledState()
{
_enabled = !_enabled;
menuStrip1.Enabled = _enabled;
tabController.SetTabLock(!_enabled);
/* Windows (7 & 8 only?) bug #1548 has extra facets.
* parent.childcontrol.Enabled = false seems to disable the parent,
* if childcontrol had focus. Depending on optimization steps,
* parent.childcontrol.Enabled = true does not necessarily
* re-enable the parent.*/
if (_enabled)
this.Focus();
}


private void UpdateRepo(object sender, DoWorkEventArgs e)
{
try
Expand Down Expand Up @@ -114,7 +98,7 @@ private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e)
{
case ReinstallModuleKraken rmk:
// Re-enable the UI for the install flow
Util.Invoke(this, SwitchEnabledState);
EnableMainWindow();
Wait.StartWaiting(InstallMods, PostInstallMods, true,
new KeyValuePair<List<ModChange>, RelationshipResolverOptions>(
rmk.Modules
Expand All @@ -136,24 +120,24 @@ private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e)
{
case RepoUpdateResult.NoChanges:
AddStatusMessage(Properties.Resources.MainRepoUpToDate);
HideWaitDialog(true);
HideWaitDialog();
// Load rows if grid empty, otherwise keep current
if (ManageMods.ModGrid.Rows.Count < 1)
{
ManageMods_OnRefresh();
}
else
{
Util.Invoke(this, SwitchEnabledState);
EnableMainWindow();
Util.Invoke(this, ManageMods.ModGrid.Select);
}
SetupDefaultSearch();
break;

case RepoUpdateResult.Failed:
AddStatusMessage(Properties.Resources.MainRepoFailed);
HideWaitDialog(false);
Util.Invoke(this, SwitchEnabledState);
HideWaitDialog();
EnableMainWindow();
Util.Invoke(this, ManageMods.ModGrid.Select);
SetupDefaultSearch();
break;
Expand All @@ -163,7 +147,7 @@ private void PostUpdateRepo(object sender, RunWorkerCompletedEventArgs e)
AddStatusMessage(Properties.Resources.MainRepoSuccess);
ShowRefreshQuestion();
UpgradeNotification();
Util.Invoke(this, SwitchEnabledState);
EnableMainWindow();
ManageMods_OnRefresh(oldModules);
break;
}
Expand Down
6 changes: 2 additions & 4 deletions GUI/Main/MainTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ public partial class Main
private void viewPlayTimeStripMenuItem_Click(object sender, EventArgs e)
{
PlayTime.loadAllPlayTime(manager);
menuStrip1.Enabled = false;
tabController.ShowTab("PlayTimeTabPage", 2);
tabController.SetTabLock(true);
DisableMainWindow();
}

private void PlayTime_Done()
{
UpdateStatusBar();
tabController.ShowTab("ManageModsTabPage");
tabController.HideTab("PlayTimeTabPage");
tabController.SetTabLock(false);
menuStrip1.Enabled = true;
EnableMainWindow();
}
}
}
12 changes: 5 additions & 7 deletions GUI/Main/MainWait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public void ShowWaitDialog()
});
}

public void HideWaitDialog(bool success)
public void HideWaitDialog()
{
Util.Invoke(this, () =>
{
Wait.Finish(success);
Wait.Finish();
RecreateDialogs();

tabController.HideTab("WaitTabPage");
Expand All @@ -46,7 +46,7 @@ public void FailWaitDialog(string statusMsg, string logMsg, string description)
});
Util.Invoke(WaitTabPage, () => {
RecreateDialogs();
Wait.Finish(false);
Wait.Finish();
SetProgress(100);
});
Wait.AddLogMessage(logMsg);
Expand Down Expand Up @@ -82,10 +82,8 @@ public void Wait_OnRetry()

public void Wait_OnOk()
{
Util.Invoke(this, () => Enabled = true);
Util.Invoke(menuStrip1, () => menuStrip1.Enabled = true);
tabController.SetTabLock(false);
HideWaitDialog(false);
EnableMainWindow();
HideWaitDialog();
}
}
}