Skip to content

Commit

Permalink
Merge pull request KSP-CKAN#60 from AlexanderDzhoganov/remember_windo…
Browse files Browse the repository at this point in the history
…w_pos

Remember window position + size on close
  • Loading branch information
AlexanderDzhoganov committed Mar 4, 2015
2 parents 41e917d + 538f8c9 commit e88ea25
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 49 deletions.
15 changes: 15 additions & 0 deletions App.config
@@ -1,9 +1,24 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="CKAN.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<loadFromRemoteSources enabled="true" />
</runtime>
<userSettings>
<CKAN.Properties.Settings>
<setting name="MainWindowPos" serializeAs="String">
<value>0, 0</value>
</setting>
<setting name="MainWindowSize" serializeAs="String">
<value>1024, 500</value>
</setting>
</CKAN.Properties.Settings>
</userSettings>
</configuration>
1 change: 1 addition & 0 deletions Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 62 additions & 41 deletions Main.cs
Expand Up @@ -46,7 +46,7 @@ public partial class Main

public KSP CurrentInstance
{
get { return manager.CurrentInstance; }
get { return manager.CurrentInstance; }
}

public KSPManager Manager
Expand All @@ -71,15 +71,15 @@ public Main(string[] cmdlineArgs, GUIUser User, bool showConsole)

controlFactory = new ControlFactory();
Instance = this;
mainModList = new MainModList(source => UpdateFilters(this));
mainModList = new MainModList(source => UpdateFilters(this));
InitializeComponent();

// We need to initialize error dialog first to display errors
m_ErrorDialog = controlFactory.CreateControl<ErrorDialog>();

// We want to check our current instance is null first, as it may
// have already been set by a command-line option.
Manager = new KSPManager(User);
Manager = new KSPManager(User);
if (CurrentInstance == null && manager.GetPreferredInstance() == null)
{
Hide();
Expand Down Expand Up @@ -119,7 +119,7 @@ public Main(string[] cmdlineArgs, GUIUser User, bool showConsole)
}

void ModList_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
{
ModList_CellContentClick(sender, null);
}

Expand All @@ -132,7 +132,7 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
return true;
case (Keys.Control | Keys.S):
var registry = RegistryManager.Instance(CurrentInstance).registry;
if (mainModList.ComputeChangeSetFromModList(registry,CurrentInstance).Any())
if (mainModList.ComputeChangeSetFromModList(registry, CurrentInstance).Any())
{
ApplyToolButton_Click(null, null);
}
Expand All @@ -145,13 +145,34 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)

public static Main Instance { get; private set; }

private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.MainWindowPos = this.Location;

// Copy window size to app settings
if (this.WindowState == FormWindowState.Normal)
{
Properties.Settings.Default.MainWindowSize = this.Size;
}
else
{
Properties.Settings.Default.MainWindowSize = this.RestoreBounds.Size;
}

// Save settings
Properties.Settings.Default.Save();
}

private void Main_Load(object sender, EventArgs e)
{
m_UpdateRepoWorker = new BackgroundWorker {WorkerReportsProgress = false, WorkerSupportsCancellation = true};
this.Location = Properties.Settings.Default.MainWindowPos;
this.Size = Properties.Settings.Default.MainWindowSize;

m_UpdateRepoWorker = new BackgroundWorker { WorkerReportsProgress = false, WorkerSupportsCancellation = true };
m_UpdateRepoWorker.RunWorkerCompleted += PostUpdateRepo;
m_UpdateRepoWorker.DoWork += UpdateRepo;

m_InstallWorker = new BackgroundWorker {WorkerReportsProgress = true, WorkerSupportsCancellation = true};
m_InstallWorker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true };
m_InstallWorker.RunWorkerCompleted += PostInstallMods;
m_InstallWorker.DoWork += InstallMods;

Expand Down Expand Up @@ -186,9 +207,9 @@ private void Main_Load(object sender, EventArgs e)
}

int i = 0;
foreach(DataGridViewRow row in ModList.Rows)
foreach (DataGridViewRow row in ModList.Rows)
{
var module = ((GUIMod) row.Tag).ToCkanModule();
var module = ((GUIMod)row.Tag).ToCkanModule();
if (identifier == module.identifier)
{
ModList.FirstDisplayedScrollingRowIndex = i;
Expand All @@ -205,7 +226,7 @@ private void Main_Load(object sender, EventArgs e)
{
Directory.CreateDirectory(pluginsPath);
}

m_PluginController = new PluginController(pluginsPath, true);
}

Expand All @@ -218,7 +239,7 @@ private void MarkAllUpdatesToolButton_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in ModList.Rows)
{
var mod = ((GUIMod) row.Tag).ToCkanModule();
var mod = ((GUIMod)row.Tag).ToCkanModule();
var registry = RegistryManager.Instance(CurrentInstance).registry;
if (!registry.IsInstalled(mod.identifier))
{
Expand Down Expand Up @@ -255,7 +276,7 @@ private void ModList_SelectedIndexChanged(object sender, EventArgs e)
return;
}

var module = ((GUIMod) selectedItem.Tag).ToCkanModule();
var module = ((GUIMod)selectedItem.Tag).ToCkanModule();
if (module == null)
{
return;
Expand Down Expand Up @@ -286,20 +307,20 @@ private void FilterByNameTextBox_TextChanged(object sender, EventArgs e)
/// with name begining with the key pressed.
/// </summary>
private void ModList_KeyPress(object sender, KeyPressEventArgs e)
{
var rows = ModList.Rows.Cast<DataGridViewRow>().Where(row=>row.Visible);
var does_name_begin_with_char = new Func<DataGridViewRow,bool>(row =>
{
var modname = ((GUIMod) row.Tag).ToCkanModule().name;
{
var rows = ModList.Rows.Cast<DataGridViewRow>().Where(row => row.Visible);
var does_name_begin_with_char = new Func<DataGridViewRow, bool>(row =>
{
var modname = ((GUIMod)row.Tag).ToCkanModule().name;
var key = e.KeyChar.ToString();
return modname.StartsWith(key, StringComparison.OrdinalIgnoreCase);
});
ModList.ClearSelection();
DataGridViewRow match = rows.FirstOrDefault(does_name_begin_with_char);
if (match != null)
{
{
match.Selected = true;

if (Util.IsLinux)
{
try
Expand All @@ -312,11 +333,11 @@ private void ModList_KeyPress(object sender, KeyPressEventArgs e)
var safe_set_method = vertical_scroll_bar.GetType().GetMethod("SafeValueSet",
BindingFlags.NonPublic | BindingFlags.Instance);

first_row_index.SetValue(ModList, match.Index);
first_row_index.SetValue(ModList, match.Index);
safe_set_method.Invoke(vertical_scroll_bar,
new object[] {match.Index*match.Height});
new object[] { match.Index * match.Height });
}
catch
catch
{
//Compared to crashing ignoring the keypress is fine.
}
Expand All @@ -327,10 +348,10 @@ private void ModList_KeyPress(object sender, KeyPressEventArgs e)
{
//Not the best of names. Why not FirstVisableRowIndex?
ModList.FirstDisplayedScrollingRowIndex = match.Index;
}
}
}
}


}

/// <summary>
Expand All @@ -339,7 +360,7 @@ private void ModList_KeyPress(object sender, KeyPressEventArgs e)
/// </summary>
private void ModList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

ModList.CommitEdit(DataGridViewDataErrorContexts.Commit);
}

Expand All @@ -356,10 +377,10 @@ private void ModList_CellValueChanged(object sender, DataGridViewCellEventArgs e
if (columnIndex < 2)
{
var checkbox = (DataGridViewCheckBoxCell)gridViewCell;
if (columnIndex==0)

if (columnIndex == 0)
{
((GUIMod) row.Tag).IsInstallChecked = (bool) checkbox.Value;
((GUIMod)row.Tag).IsInstallChecked = (bool)checkbox.Value;
}
else if (columnIndex == 1)
{
Expand All @@ -386,7 +407,7 @@ private void ModList_CellValueChanged(object sender, DataGridViewCellEventArgs e
return;
}


if (gridViewCell is DataGridViewLinkCell)
{
var cell = gridViewCell as DataGridViewLinkCell;
Expand Down Expand Up @@ -445,7 +466,7 @@ private void ContentsDownloadButton_Click(object sender, EventArgs e)
return;
}

var module = ((GUIMod) selectedItem.Tag).ToCkanModule();
var module = ((GUIMod)selectedItem.Tag).ToCkanModule();
if (module == null)
{
return;
Expand Down Expand Up @@ -563,17 +584,17 @@ private void launchKSPToolStripMenuItem_Click(object sender, EventArgs e)
string binary = lst[0];
string args = String.Empty;

for(int i = 1; i < lst.Length; i++)
for (int i = 1; i < lst.Length; i++)
{
args += lst[i] + " ";
}

try
{
Directory.SetCurrentDirectory(CurrentInstance.GameDir());
Process.Start(binary, args);
}
catch(Exception exception)
catch (Exception exception)
{
GUI.user.RaiseError("Couldn't start KSP. {0}.", exception.Message);
}
Expand Down Expand Up @@ -617,7 +638,7 @@ private void installFromckanToolStripMenuItem_Click(object sender, EventArgs e)
{
m_OpenFileDialog.Filter = "CKAN metadata (*.ckan)|*.ckan";

if(m_OpenFileDialog.ShowDialog() == DialogResult.OK)
if (m_OpenFileDialog.ShowDialog() == DialogResult.OK)
{
var path = m_OpenFileDialog.FileName;
CkanModule module = null;
Expand All @@ -626,12 +647,12 @@ private void installFromckanToolStripMenuItem_Click(object sender, EventArgs e)
{
module = CkanModule.FromFile(path);
}
catch(Kraken kraken)
catch (Kraken kraken)
{
m_User.RaiseError(kraken.Message + ": " + kraken.InnerException.Message);
return;
}
catch(Exception ex)
catch (Exception ex)
{
m_User.RaiseError(ex.Message);
return;
Expand Down Expand Up @@ -674,8 +695,8 @@ public class GUIUser : NullUser
public Action<string, object[]> displayMessage;
public Action<string, object[]> displayError;
public DisplayYesNo displayYesNo;


protected override bool DisplayYesNoDialog(string message)
{
if (displayYesNo == null)
Expand Down Expand Up @@ -707,6 +728,6 @@ public override int WindowWidth
get { return -1; }
}


}
}
28 changes: 26 additions & 2 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions Properties/Settings.settings
@@ -1,7 +1,12 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="CKAN.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="MainWindowPos" Type="System.Drawing.Point" Scope="User">
<Value Profile="(Default)">0, 0</Value>
</Setting>
<Setting Name="MainWindowSize" Type="System.Drawing.Size" Scope="User">
<Value Profile="(Default)">1024, 500</Value>
</Setting>
</Settings>
</SettingsFile>

0 comments on commit e88ea25

Please sign in to comment.