Menu

[38707f]: / FormSettings.cs  Maximize  Restore  History

Download this file

135 lines (122 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using GitForce.Settings.Panels;
namespace GitForce
{
/// <summary>
/// Define an interface for option panels; at minimum they need to
/// implement function that initializes and sets the changed values
/// </summary>
interface IUserSettings
{
void Init(string[] config);
void Focus(bool focused);
void ApplyChanges();
}
public sealed partial class FormSettings : Form
{
/// <summary>
/// Get all global configuration strings and assign various panel controls.
/// This is placed first, before initializing the user panels, so that the
/// strings are accessible to individual panels should they need to use them.
/// </summary>
private readonly string[] config = ClassGit.Run("config --global --list -z").ToString().Split('\0');
/// <summary>
/// Create a lookup from panel names (which are set in each corresponding node
/// of an option set tree view) to the actual option panel instance:
/// </summary>
private readonly Dictionary<string, UserControl> panels = new Dictionary<string, UserControl> {
{ "Global", new ControlGlobal() },
{ "User", new ControlUser() },
{ "Status", new ControlStatus() },
{ "Commits", new ControlCommits() },
{ "Gitignore", new ControlGitignore() },
{ "Gitconfig", new ControlGitconfig() },
{ "Files", new ControlFiles() },
{ "ViewEdit", new ControlViewEdit() },
{ "Diff", new ControlDiff() },
{ "Merge", new ControlMerge() },
{ "DoubleClick", new ControlDoubleClick() },
{ "Options", new ControlOptions() },
{ "Aliases", new ControlAliases() },
{ "Ssl", new ControlSsl() },
{ "Specifications", new ControlSpecifications() },
};
/// <summary>
/// Settings panel that is currently on the top
/// </summary>
private UserControl current;
public FormSettings()
{
InitializeComponent();
ClassWinGeometry.Restore(this);
Cursor.Current = Cursors.WaitCursor;
// Add all user panels to the base options panel; call their init
foreach (KeyValuePair<string, UserControl> key in panels)
{
panel.Controls.Add(key.Value);
(key.Value as IUserSettings).Init(config);
key.Value.Dock = DockStyle.Fill;
}
// Expand the tree and select the first node
treeSections.ExpandAll();
treeSections.SelectedNode = treeSections.Nodes[0].Nodes[0];
Cursor.Current = Cursors.Default;
}
/// <summary>
/// Form is closing.
/// </summary>
private void FormSettingsFormClosing(object sender, FormClosingEventArgs e)
{
ClassWinGeometry.Save(this);
}
/// <summary>
/// Selecting the tree node brings up the corresponding user control
/// </summary>
private void TreeSectionsAfterSelect(object sender, TreeViewEventArgs e)
{
string panelName = e.Node.Tag as string;
if (panelName != null && panels.ContainsKey(panelName))
{
if (current != null)
(current as IUserSettings).Focus(false);
current = panels[panelName];
current.BringToFront();
(current as IUserSettings).Focus(true);
}
}
/// <summary>
/// User clicked on the Apply button - store all changes to the current
/// setting panel, but not to any other. Hitting OK will store all panels.
/// Hitting Cancel will void all changes in any panel done since the last
/// time Apply button was pressed.
/// </summary>
private void BtApplyClick(object sender, EventArgs e)
{
(current as IUserSettings).ApplyChanges();
}
/// <summary>
/// User clicked on the OK button - apply all modified settings before
/// returning from the dialog
/// </summary>
private void BtOkClick(object sender, EventArgs e)
{
foreach (KeyValuePair<string, UserControl> key in panels)
(key.Value as IUserSettings).ApplyChanges();
}
}
/// <summary>
/// This class is a static helper class that simply marks a tag field
/// of a calling control with a non-empty value. It should be called
/// on text/value/state changed event of a control when the set operation
/// may be expensive (such are calling git to set configuration parameters)
/// </summary>
public static class ControlDirtyHelper
{
public static void ControlDirty(object sender, EventArgs e)
{
(sender as Control).Tag = "1";
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.