Skip to content

Commit

Permalink
- option to persist column layout for each tab
Browse files Browse the repository at this point in the history
  • Loading branch information
PredatH0r committed Sep 10, 2015
1 parent 4c453c1 commit a45ec29
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 7 deletions.
12 changes: 12 additions & 0 deletions ServerBrowser/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions ServerBrowser/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,8 @@
<Setting Name="TabIndex" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="ColumnLayoutPerTab" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
21 changes: 19 additions & 2 deletions ServerBrowser/ServerBrowserForm.Designer.cs

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

29 changes: 26 additions & 3 deletions ServerBrowser/ServerBrowserForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ private void SetViewModel(TabViewModel vm)
this.cbGetEmpty.Checked = vm.GetEmptyServers;
this.cbGetFull.Checked = vm.GetFullServers;
this.comboQueryLimit.Text = vm.MasterServerQueryLimit.ToString();

this.gvServers.ActiveFilterString = vm.GridFilter;

UpdatePanelVisibility();
this.miFindServers.Enabled = vm.Source == TabViewModel.SourceType.MasterServer;
}
Expand Down Expand Up @@ -324,6 +326,7 @@ protected virtual void ApplyAppSettings()
this.rbUpdateListAndStatus.Checked = opt.AutoUpdateList;
this.rbUpdateStatusOnly.Checked = opt.AutoUpdateInfo;
this.cbFavServersOnTop.Checked = opt.KeepFavServersOnTop;
this.cbRememberColumnLayout.Checked = opt.ColumnLayoutPerTab;

// load favorite servers
this.favServers.Clear();
Expand Down Expand Up @@ -367,6 +370,7 @@ protected virtual void SaveAppSettings()
opt.AutoUpdateInfo = this.rbUpdateStatusOnly.Checked;
opt.Skin = UserLookAndFeel.Default.SkinName;
opt.TabIndex = this.tabControl.SelectedTabPageIndex;
opt.ColumnLayoutPerTab = this.cbRememberColumnLayout.Checked;

var sb = new StringBuilder();
foreach (var fav in this.favServers)
Expand Down Expand Up @@ -423,7 +427,12 @@ protected virtual void UpdateViewModel()
vm.MasterServerQueryLimit = Convert.ToInt32(this.comboQueryLimit.Text);

vm.GridFilter = this.gvServers.ActiveFilterString;

if (this.cbRememberColumnLayout.Checked)
{
var strm = new MemoryStream();
this.gvServers.SaveLayoutToStream(strm);
vm.ServerGridLayout = strm;
}
vm.serverSource = this.CreateServerSource(vm.MasterServer);
vm.gameExtension = this.extenders.Get((Game)vm.InitialGameID);
}
Expand Down Expand Up @@ -470,21 +479,34 @@ private void SetSteamAppId(int appId)
int index = this.gameIdForComboBoxIndex.IndexOf((Game)appId);
if (index >= 0)
this.comboGames.SelectedIndex = index;
else
else if (appId != 0)
this.comboGames.Text = appId.ToString();
else
this.comboGames.EditValue = null;

--this.ignoreUiEvents;
}
#endregion

#region InitGameExtension()
private void InitGameExtension()
{
this.viewModel.gameExtension = this.extenders.Get((Game)this.viewModel.InitialGameID);
var ext = this.extenders.Get((Game) this.viewModel.InitialGameID);
if (ext != this.viewModel.gameExtension)
{
this.viewModel.ServerGridLayout = null;
this.viewModel.gameExtension = ext;
}

this.gvServers.BeginUpdate();
this.ResetGridColumns(this.gvServers);
this.viewModel.gameExtension.CustomizeServerGridColumns(gvServers);
this.gvServers.EndUpdate();
if (viewModel.ServerGridLayout != null && this.cbRememberColumnLayout.Checked)
{
viewModel.ServerGridLayout.Seek(0, SeekOrigin.Begin);
this.gvServers.RestoreLayoutFromStream(viewModel.ServerGridLayout);
}

this.gvPlayers.BeginUpdate();
this.ResetGridColumns(this.gvPlayers);
Expand Down Expand Up @@ -1520,6 +1542,7 @@ private void tabControl_SelectedPageChanged(object sender, TabPageChangedEventAr
if (this.ignoreUiEvents > 0) return;
this.SetViewModel((TabViewModel)e.Page.Tag);
this.UpdateViews(true);

if (this.viewModel.servers == null)
this.ReloadServerList();
else if (this.viewModel.Source != TabViewModel.SourceType.MasterServer)
Expand Down
14 changes: 12 additions & 2 deletions ServerBrowser/TabViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using ChanSort.Api;
using QueryMaster;
Expand Down Expand Up @@ -26,6 +28,7 @@ public enum SourceType { MasterServer, CustomList, Favorites }
public int MasterServerQueryLimit { get; set; }

public string GridFilter { get; set; }
public MemoryStream ServerGridLayout { get; set; }
public SourceType Source { get; set; }
public int ImageIndex => Source == SourceType.Favorites ? 3 : Source == SourceType.CustomList ? 12 : -1;

Expand Down Expand Up @@ -58,6 +61,7 @@ public void AssignFrom(IViewModel opt)
this.servers = vm.servers;
this.gameExtension = vm.gameExtension;
this.GridFilter = vm.GridFilter;
this.ServerGridLayout = vm.ServerGridLayout;
}
#endregion

Expand All @@ -75,6 +79,11 @@ public void LoadFromIni(IniFile.Section ini, GameExtensionPool pool)
this.GetFullServers = ini.GetBool("GetFullServers", true);
this.MasterServerQueryLimit = ini.GetInt("MasterServerQueryLimit", 500);
this.GridFilter = ini.GetString("GridFilter");

var layout = ini.GetString("GridLayout");
if (!string.IsNullOrEmpty(layout))
this.ServerGridLayout = new MemoryStream(Convert.FromBase64String(layout));

this.gameExtension = pool.Get((Game) this.InitialGameID);

if (this.Source == SourceType.CustomList)
Expand Down Expand Up @@ -104,7 +113,8 @@ public void WriteToIni(StringBuilder ini)
ini.Append("GetFullServers=").AppendLine(this.GetFullServers ? "1" : "0");
ini.Append("MasterServerQueryLimit=").Append(this.MasterServerQueryLimit).AppendLine();
ini.Append("GridFilter=").AppendLine(this.GridFilter);

if (this.ServerGridLayout != null)
ini.Append("GridLayout=").AppendLine(Convert.ToBase64String(this.ServerGridLayout.GetBuffer(), 0, (int) this.ServerGridLayout.Length));
if (this.Source == SourceType.CustomList)
{
ini.Append("Servers=");
Expand Down
3 changes: 3 additions & 0 deletions ServerBrowser/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<setting name="TabIndex" serializeAs="String">
<value>0</value>
</setting>
<setting name="ColumnLayoutPerTab" serializeAs="String">
<value>False</value>
</setting>
</ServerBrowser.Properties.Settings>
</userSettings>
<runtime>
Expand Down

0 comments on commit a45ec29

Please sign in to comment.