Skip to content

Commit

Permalink
Merge pull request #10 from Hefaistos68/development
Browse files Browse the repository at this point in the history
Major changes to autostart and always admin
  • Loading branch information
Hefaistos68 authored Sep 11, 2023
2 parents e991916 + cb7dfd5 commit b622058
Show file tree
Hide file tree
Showing 28 changed files with 2,365 additions and 380 deletions.
3 changes: 3 additions & 0 deletions VSLauncherX/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<setting name="ColumnOptionsVisible" serializeAs="String">
<value>True</value>
</setting>
<setting name="AutoStart" serializeAs="String">
<value>False</value>
</setting>
</VSLauncher.Properties.Settings>
</userSettings>
</configuration>
218 changes: 218 additions & 0 deletions VSLauncherX/Controls/VisualStudioCombobox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
using VSLauncher.DataModel;

namespace VSLauncher.Controls
{
/// <summary>
/// The visual studio combobox.
/// </summary>
public class VisualStudioCombobox : ComboBox
{
private VisualStudioInstanceManager visualStudioVersions = new VisualStudioInstanceManager();
private bool showDefault;

public VisualStudioCombobox()
{
DrawMode = DrawMode.OwnerDrawFixed;
DropDownStyle = ComboBoxStyle.DropDownList;
IntegralHeight = false;
ItemHeight = 26;
DrawItem += CustomDrawItem;

Items.AddRange(visualStudioVersions.All.ToArray());
}

/// <summary>
/// Gets or sets a value indicating whether to show default.
/// </summary>
public bool ShowDefault
{
get => showDefault;
set
{
showDefault = value;

if (value)
{
Items.Insert(0, "<default>");
}
else
{
if (Items.Count > 0 && Items[0] is string)
{
Items.RemoveAt(0);
}
}
}
}

/// <summary>
/// Gets the versions.
/// </summary>
public List<VisualStudioInstance> Versions { get { return visualStudioVersions.All; } }

/// <summary>
/// Gets the selected item.
/// </summary>
public new VisualStudioInstance? SelectedItem
{
get
{
if (ShowDefault)
{
return base.SelectedIndex > 0 ? (VisualStudioInstance)base.SelectedItem : null;
}

return (VisualStudioInstance)base.SelectedItem;
}
set
{
base.SelectedItem = value;
}
}

/// <summary>
/// Gets or sets the selected index, accounting for the default item which will result in -1
/// </summary>
public new int SelectedIndex
{
get
{
return ShowDefault ? base.SelectedIndex - 1 : base.SelectedIndex;
}
set
{
base.SelectedIndex = value;
}
}

/// <summary>
/// Gets a value indicating whether default is selected.
/// </summary>
public bool IsDefaultSelected
{
get
{
return ShowDefault && base.SelectedIndex == 0;
}
}

/// <summary>
/// Selects the default item if existing
/// </summary>
public void SelectDefault()
{
if (ShowDefault)
{
SelectedIndex = 0;
}
}

protected override void OnDropDown(EventArgs e)
{
Items.Clear();

if (ShowDefault)
{
Items.Add("<default>");
}

Items.AddRange(visualStudioVersions.All.ToArray());

base.OnDropDown(e);
}

/// <summary>
/// Selects the active item from a version string (exact or major version), a shortname or an identifier
/// </summary>
/// <param name="v">The v.</param>
internal void SelectFromVersion(string? v)
{
if (string.IsNullOrWhiteSpace(v))
{
if (ShowDefault)
{
if (v != null) // v is "" so select the default
{
SelectDefault();
return;
}
}

// any NULL value will return the highest version
v = visualStudioVersions.HighestVersion().Version;
}

// find either by exact version or by short name containing the version
var i = visualStudioVersions.All.FindIndex(x => x.Version == v);
if (i >= 0)
{
SelectedIndex = ShowDefault ? 1 + i : i;
return;
}

var k = visualStudioVersions.All.FindIndex(x => x.Version.StartsWith(v));
if (k >= 0)
{
SelectedIndex = ShowDefault ? 1 + k : k;
return;
}

// by year
var n = visualStudioVersions.All.FindIndex(x => x.ShortName.Contains(v));
if (n >= 0)
{
SelectedIndex = ShowDefault ? 1 + n : n;
return;
}

// by identifier
var o = visualStudioVersions.All.FindIndex(x => x.Identifier == v);
if (o >= 0)
{
SelectedIndex = ShowDefault ? 1 + o : o;
return;
}

SelectedIndex = -1;
}

/// <summary>
/// Custom draws the item
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void CustomDrawItem(object sender, DrawItemEventArgs e)
{
// draw the selected item with the Visual Studio Icon and the version as text
if (e.Index >= 0 && e.Index <= visualStudioVersions.Count)
{
e.DrawBackground();

var height = 16;

Rectangle iconRect = new Rectangle(e.Bounds.Left + Margin.Left,
e.Bounds.Top + (ItemHeight - height) / 2,
height, height);
if (ShowDefault)
{
if (e.Index > 0)
{
e.Graphics.DrawIcon(visualStudioVersions[e.Index - 1].AppIcon, iconRect);
e.Graphics.DrawString(visualStudioVersions[e.Index - 1].Name, e.Font, Brushes.Black, e.Bounds.Left + 20, e.Bounds.Top + 4);
}
else
{
e.Graphics.DrawIcon(Resources.AppLogo, iconRect);
e.Graphics.DrawString("<default>", e.Font, Brushes.Black, e.Bounds.Left + 20, e.Bounds.Top + 4);
}
}
else
{
e.Graphics.DrawIcon(visualStudioVersions[e.Index].AppIcon, iconRect);
e.Graphics.DrawString(visualStudioVersions[e.Index].Name, e.Font, Brushes.Black, e.Bounds.Left + 20, e.Bounds.Top + 4);
}
}
}

}
}
6 changes: 4 additions & 2 deletions VSLauncherX/Forms/dlgExecuteVisualStudio.Designer.cs

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

27 changes: 20 additions & 7 deletions VSLauncherX/Forms/dlgSettings.Designer.cs

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

2 changes: 2 additions & 0 deletions VSLauncherX/Forms/dlgSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public dlgSettings()
private void btnOk_Click(object sender, EventArgs e)
{
Properties.Settings.Default.AlwaysAdmin = chkAlwaysAdmin.Checked;
Properties.Settings.Default.AutoStart = chkAutostart.Checked;
Properties.Settings.Default.SynchronizeVS = chkSync.Checked;
Properties.Settings.Default.ShowPathForSolutions = chkShowPath.Checked;
Properties.Settings.Default.Save();
}

private void dlgSettings_Load(object sender, EventArgs e)
{
chkAutostart.Checked = Properties.Settings.Default.AutoStart;
chkAlwaysAdmin.Checked = Properties.Settings.Default.AlwaysAdmin;
chkSync.Checked = Properties.Settings.Default.SynchronizeVS;
chkShowPath.Checked = Properties.Settings.Default.ShowPathForSolutions;
Expand Down
2 changes: 1 addition & 1 deletion VSLauncherX/Forms/dlgSettings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
Expand Down
Loading

0 comments on commit b622058

Please sign in to comment.