diff --git a/Sunfish/Sunfish/Configurator/ConfigurationBool.cs b/Sunfish/Sunfish/Configurator/ConfigurationBool.cs index 6bc5390..737ef0a 100644 --- a/Sunfish/Sunfish/Configurator/ConfigurationBool.cs +++ b/Sunfish/Sunfish/Configurator/ConfigurationBool.cs @@ -1,4 +1,7 @@ -namespace DolphinWebXplorer2.Configurator +using System.Drawing; +using System.Windows.Forms; + +namespace DolphinWebXplorer2.Configurator { public class ConfigurationBool : ConfigurationElement { @@ -6,6 +9,21 @@ { } + public override bool isEmpty(Control c) + { + throw new System.NotImplementedException(); + } + + public override object getValue(Control c) + { + CheckBox cb = c as CheckBox; + if (cb == null) + return null; + return cb.Checked; + } + public bool DefaultValue { get; set; } + + public override Color UIMandatoryColor => throw new System.NotImplementedException(); } } diff --git a/Sunfish/Sunfish/Configurator/ConfigurationElement.cs b/Sunfish/Sunfish/Configurator/ConfigurationElement.cs index 1031e50..545c8d1 100644 --- a/Sunfish/Sunfish/Configurator/ConfigurationElement.cs +++ b/Sunfish/Sunfish/Configurator/ConfigurationElement.cs @@ -1,4 +1,7 @@ -namespace DolphinWebXplorer2.Configurator +using System.Drawing; +using System.Windows.Forms; + +namespace DolphinWebXplorer2.Configurator { public abstract class ConfigurationElement { @@ -8,8 +11,15 @@ Label = label; } + public abstract bool isEmpty(Control c); + + public abstract object getValue(Control c); + public string Id { get; } public string Label { get; } public string Tooltip { get; set; } + public bool Mandatory { get; set; } + + public abstract Color UIMandatoryColor { get; } } } diff --git a/Sunfish/Sunfish/Configurator/ConfigurationMessage.cs b/Sunfish/Sunfish/Configurator/ConfigurationMessage.cs index 90234ea..4a9fea0 100644 --- a/Sunfish/Sunfish/Configurator/ConfigurationMessage.cs +++ b/Sunfish/Sunfish/Configurator/ConfigurationMessage.cs @@ -1,4 +1,7 @@ -namespace DolphinWebXplorer2.Configurator +using System.Drawing; +using System.Windows.Forms; + +namespace DolphinWebXplorer2.Configurator { class ConfigurationMessage : ConfigurationElement { @@ -13,7 +16,19 @@ Message = message; } + public override bool isEmpty(Control c) + { + throw new System.NotImplementedException(); + } + + public override object getValue(Control c) + { + return null; + } + public MessageType Type { get; } public string Message { get; } + + public override Color UIMandatoryColor => throw new System.NotImplementedException(); } } diff --git a/Sunfish/Sunfish/Configurator/ConfigurationString.cs b/Sunfish/Sunfish/Configurator/ConfigurationString.cs index ef8b5d4..56f25fb 100644 --- a/Sunfish/Sunfish/Configurator/ConfigurationString.cs +++ b/Sunfish/Sunfish/Configurator/ConfigurationString.cs @@ -1,4 +1,7 @@ -namespace DolphinWebXplorer2.Configurator +using System.Drawing; +using System.Windows.Forms; + +namespace DolphinWebXplorer2.Configurator { public class ConfigurationString : ConfigurationElement { @@ -6,9 +9,27 @@ { } + public override bool isEmpty(Control c) + { + TextBox tb = c as TextBox; + if (tb == null) + return false; + return string.IsNullOrWhiteSpace(tb.Text); + } + + public override object getValue(Control c) + { + TextBox tb = c as TextBox; + if (tb == null) + return null; + return tb.Text; + } + public string DefaultValue { get; set; } public bool IsPassword { get; set; } public bool IsDirectoiryPath { get; set; } public bool IsFilePath { get; set; } + + public override Color UIMandatoryColor => Color.LightGoldenrodYellow; } } diff --git a/Sunfish/Sunfish/FServiceConf.Designer.cs b/Sunfish/Sunfish/FServiceConf.Designer.cs index 7c67a7c..91c6bfa 100644 --- a/Sunfish/Sunfish/FServiceConf.Designer.cs +++ b/Sunfish/Sunfish/FServiceConf.Designer.cs @@ -46,9 +46,10 @@ // lbType // this.lbType.AutoSize = true; - this.lbType.Location = new System.Drawing.Point(11, 9); + this.lbType.Location = new System.Drawing.Point(7, 6); + this.lbType.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lbType.Name = "lbType"; - this.lbType.Size = new System.Drawing.Size(47, 20); + this.lbType.Size = new System.Drawing.Size(34, 13); this.lbType.TabIndex = 0; this.lbType.Text = "Type:"; // @@ -58,9 +59,10 @@ | System.Windows.Forms.AnchorStyles.Right))); this.cbType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbType.FormattingEnabled = true; - this.cbType.Location = new System.Drawing.Point(25, 32); + this.cbType.Location = new System.Drawing.Point(17, 21); + this.cbType.Margin = new System.Windows.Forms.Padding(2); this.cbType.Name = "cbType"; - this.cbType.Size = new System.Drawing.Size(380, 28); + this.cbType.Size = new System.Drawing.Size(255, 21); this.cbType.TabIndex = 1; this.toolTip1.SetToolTip(this.cbType, "Type of service."); this.cbType.SelectedIndexChanged += new System.EventHandler(this.cbType_SelectedIndexChanged); @@ -68,9 +70,10 @@ // lbName // this.lbName.AutoSize = true; - this.lbName.Location = new System.Drawing.Point(12, 77); + this.lbName.Location = new System.Drawing.Point(8, 50); + this.lbName.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.lbName.Name = "lbName"; - this.lbName.Size = new System.Drawing.Size(55, 20); + this.lbName.Size = new System.Drawing.Size(38, 13); this.lbName.TabIndex = 2; this.lbName.Text = "Name:"; // @@ -78,9 +81,11 @@ // this.tbName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.tbName.Location = new System.Drawing.Point(25, 100); + this.tbName.BackColor = System.Drawing.Color.LightGoldenrodYellow; + this.tbName.Location = new System.Drawing.Point(17, 65); + this.tbName.Margin = new System.Windows.Forms.Padding(2); this.tbName.Name = "tbName"; - this.tbName.Size = new System.Drawing.Size(299, 26); + this.tbName.Size = new System.Drawing.Size(199, 20); this.tbName.TabIndex = 3; this.toolTip1.SetToolTip(this.tbName, "Name of the service.\r\n(only for management)"); // @@ -88,9 +93,10 @@ // this.cbActive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.cbActive.AutoSize = true; - this.cbActive.Location = new System.Drawing.Point(330, 102); + this.cbActive.Location = new System.Drawing.Point(223, 67); + this.cbActive.Margin = new System.Windows.Forms.Padding(2); this.cbActive.Name = "cbActive"; - this.cbActive.Size = new System.Drawing.Size(78, 24); + this.cbActive.Size = new System.Drawing.Size(56, 17); this.cbActive.TabIndex = 4; this.cbActive.Text = "Active"; this.cbActive.UseVisualStyleBackColor = true; @@ -98,9 +104,10 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(12, 143); + this.label1.Location = new System.Drawing.Point(8, 93); + this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(74, 20); + this.label1.Size = new System.Drawing.Size(51, 13); this.label1.TabIndex = 5; this.label1.Text = "Location:"; // @@ -108,18 +115,21 @@ // this.tbLocation.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.tbLocation.Location = new System.Drawing.Point(25, 166); + this.tbLocation.BackColor = System.Drawing.Color.LightGoldenrodYellow; + this.tbLocation.Location = new System.Drawing.Point(17, 108); + this.tbLocation.Margin = new System.Windows.Forms.Padding(2); this.tbLocation.Name = "tbLocation"; - this.tbLocation.Size = new System.Drawing.Size(380, 26); + this.tbLocation.Size = new System.Drawing.Size(255, 20); this.tbLocation.TabIndex = 6; this.toolTip1.SetToolTip(this.tbLocation, "Document root on the server:\r\nThis works as a virtual directory in the url."); // // btOk // this.btOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.btOk.Location = new System.Drawing.Point(211, 227); + this.btOk.Location = new System.Drawing.Point(141, 148); + this.btOk.Margin = new System.Windows.Forms.Padding(2); this.btOk.Name = "btOk"; - this.btOk.Size = new System.Drawing.Size(113, 38); + this.btOk.Size = new System.Drawing.Size(75, 25); this.btOk.TabIndex = 7; this.btOk.Text = "Ok"; this.btOk.UseVisualStyleBackColor = true; @@ -129,9 +139,10 @@ // this.btCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btCancel.Location = new System.Drawing.Point(337, 227); + this.btCancel.Location = new System.Drawing.Point(225, 148); + this.btCancel.Margin = new System.Windows.Forms.Padding(2); this.btCancel.Name = "btCancel"; - this.btCancel.Size = new System.Drawing.Size(82, 38); + this.btCancel.Size = new System.Drawing.Size(55, 25); this.btCancel.TabIndex = 8; this.btCancel.Text = "Cancel"; this.btCancel.UseVisualStyleBackColor = true; @@ -141,17 +152,19 @@ this.pScreen.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.pScreen.Location = new System.Drawing.Point(12, 210); + this.pScreen.Location = new System.Drawing.Point(8, 136); + this.pScreen.Margin = new System.Windows.Forms.Padding(2); this.pScreen.Name = "pScreen"; - this.pScreen.Size = new System.Drawing.Size(407, 1); + this.pScreen.Size = new System.Drawing.Size(271, 1); this.pScreen.TabIndex = 9; // // btAdv // this.btAdv.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btAdv.Location = new System.Drawing.Point(12, 227); + this.btAdv.Location = new System.Drawing.Point(8, 148); + this.btAdv.Margin = new System.Windows.Forms.Padding(2); this.btAdv.Name = "btAdv"; - this.btAdv.Size = new System.Drawing.Size(167, 38); + this.btAdv.Size = new System.Drawing.Size(111, 25); this.btAdv.TabIndex = 10; this.btAdv.Text = "Advanced Settings"; this.btAdv.UseVisualStyleBackColor = true; @@ -159,10 +172,10 @@ // FServiceConf // this.AcceptButton = this.btOk; - this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btCancel; - this.ClientSize = new System.Drawing.Size(431, 277); + this.ClientSize = new System.Drawing.Size(287, 180); this.Controls.Add(this.btAdv); this.Controls.Add(this.pScreen); this.Controls.Add(this.btCancel); @@ -175,6 +188,7 @@ this.Controls.Add(this.cbType); this.Controls.Add(this.lbType); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Margin = new System.Windows.Forms.Padding(2); this.Name = "FServiceConf"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; diff --git a/Sunfish/Sunfish/FServiceConf.cs b/Sunfish/Sunfish/FServiceConf.cs index ae396e2..4934143 100644 --- a/Sunfish/Sunfish/FServiceConf.cs +++ b/Sunfish/Sunfish/FServiceConf.cs @@ -41,19 +41,40 @@ } cbActive.Checked = ssc.Enabled; tbName.Text = ssc.Name; - tbLocation.Text = ssc.Name; + tbLocation.Text = ssc.Location; LoadScreen(); } + private bool ValidateData() + { + bool valid = true; + if (string.IsNullOrWhiteSpace(tbName.Text)) + { + valid = false; + tbName.BackColor = Color.LightCoral; + } + else + tbName.BackColor = Color.LightGoldenrodYellow; + if (string.IsNullOrWhiteSpace(tbLocation.Text)) + { + valid = false; + tbLocation.BackColor = Color.LightCoral; + } + else + tbLocation.BackColor = Color.LightGoldenrodYellow; + return valid & ValidateDynamicScreen(); + } + private void SaveData() { ssc.Type = cbType.SelectedItem == null ? null : cbType.SelectedItem.ToString(); ssc.Enabled = cbActive.Checked; ssc.Name = tbName.Text; ssc.Location = tbLocation.Text; - // TODO Save from dynamic screen + SaveDynamicScreen(); } + #region Dynamic properties private void AddElementLabel(ConfigurationElement ce, Panel p, ref int y) { if (string.IsNullOrEmpty(ce.Label)) @@ -63,8 +84,8 @@ l.Text = ce.Label; l.Top = y; l.AutoSize = true; - y += l.Height + 3; p.Controls.Add(l); + y += l.Height + 3; } private void FinishElement(Control c, ConfigurationElement ce, Panel p, ref int y) @@ -72,9 +93,9 @@ if (!string.IsNullOrEmpty(ce.Tooltip)) toolTip1.SetToolTip(c, ce.Tooltip); c.Top = y; - y += c.Height + 3; c.Tag = ce; p.Controls.Add(c); + y += c.Height + 3; } private void AddElementMessage(ConfigurationMessage ce, Panel p, ref int y) @@ -83,6 +104,11 @@ Label c = new Label(); c.Text = ce.Message; c.BorderStyle = BorderStyle.FixedSingle; + c.MaximumSize = new Size(p.ClientSize.Width - 28, int.MaxValue); + c.MinimumSize = new Size(c.MaximumSize.Width, 0); + c.Left = 14; + c.AutoSize = true; + FinishElement(c, ce, p, ref y); switch (ce.Type) { case ConfigurationMessage.MessageType.ERROR: @@ -92,14 +118,9 @@ c.BackColor = Color.FromArgb(255, 255, 255); break; case ConfigurationMessage.MessageType.WARNING: - c.BackColor = Color.WhiteSmoke; + c.BackColor = Color.PaleGoldenrod; break; } - c.MaximumSize = new Size(p.ClientSize.Width - 28, int.MaxValue); - c.MinimumSize = new Size(c.MaximumSize.Width, 0); - c.Left = 14; - c.AutoSize = true; - FinishElement(c, ce, p, ref y); } private void AddElementString(ConfigurationString ce, Panel p, ref int y) @@ -107,10 +128,13 @@ AddElementLabel(ce, p, ref y); TextBox c = new TextBox(); c.Text = ssc.GetConf(ce.Id, ce.DefaultValue); - c.Left = 14; - c.Width = p.ClientSize.Width - 28; + // WARNING: Values for standard DPI + c.Left = 9; + c.Width = p.ClientSize.Width - 16; if (ce.IsPassword) c.PasswordChar = '*'; + if (ce.Mandatory) + c.BackColor = ce.UIMandatoryColor; //TODO: Handle isDirectory and IsFile properties FinishElement(c, ce, p, ref y); } @@ -119,7 +143,7 @@ { CheckBox c = new CheckBox(); c.Text = ce.Label; - c.Checked = ssc.GetConf(ce.Id); + c.Checked = ssc.GetConf(ce.Id, ce.DefaultValue); c.Left = 14; c.Width = p.ClientSize.Width - 28; FinishElement(c, ce, p, ref y); @@ -127,6 +151,7 @@ private void LoadScreen() { + int height = Height; // Remove all pScreen.Controls.Clear(); string type = cbType.SelectedItem == null ? null : cbType.SelectedItem.ToString(); @@ -149,15 +174,53 @@ else if (ce is ConfigurationBool) AddElementBool((ConfigurationBool)ce, pScreen, ref y); } - ClientSize = new Size(ClientSize.Width, y + pScreen.Top + panelOffset); + ClientSize = new Size(ClientSize.Width, y + pScreen.Top + panelOffset + 5); + if (Visible) + Top -= (Height - height) / 2; } + private bool ValidateDynamicScreen() + { + bool valid = true; + foreach (Control c in pScreen.Controls) + { + ConfigurationElement ce = c.Tag as ConfigurationElement; + if (ce == null || !ce.Mandatory) + continue; + if (ce.isEmpty(c)) + { + valid = false; + c.BackColor = Color.LightCoral; + } + else + { + c.BackColor = ce.UIMandatoryColor; + } + } + return valid; + } + + private void SaveDynamicScreen() + { + foreach (Control c in pScreen.Controls) + { + ConfigurationElement ce = c.Tag as ConfigurationElement; + if (ce == null || ce.Id == null) + continue; + ssc.Settings[ce.Id] = ce.getValue(c); + } + } + + #endregion + private void FServiceConf_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { + if (!ValidateData()) + return; SaveData(); DialogResult = DialogResult.OK; } diff --git a/Sunfish/Sunfish/Services/WebServiceConfigurator.cs b/Sunfish/Sunfish/Services/WebServiceConfigurator.cs index e6da77e..74ff2af 100644 --- a/Sunfish/Sunfish/Services/WebServiceConfigurator.cs +++ b/Sunfish/Sunfish/Services/WebServiceConfigurator.cs @@ -1,4 +1,5 @@ using DolphinWebXplorer2.Configurator; +using System; namespace DolphinWebXplorer2.Services { @@ -29,37 +30,40 @@ Tooltip = "Folder, zip or web-file path of site document root", IsDirectoiryPath = true, IsFilePath = true, + Mandatory = true }, new ConfigurationString(CFG_INDEX,"Default document") { Tooltip = "Default document for directory path", - DefaultValue ="index.html" + DefaultValue = "index.html" }, new ConfigurationBool(CFG_SHARE,"Folder share") { - Tooltip ="Allow directory listings, switched off the server will report a forbidden message if the directory has no default file." + Tooltip = "Allow directory listings, switched off the server will report a forbidden message if the directory has no default file.", + DefaultValue = true, }, new ConfigurationBool(CFG_NAVIGATION,"Subfolder navigation") { - Tooltip ="Allow subfolder navigation." + Tooltip = "Allow subfolder navigation.", + DefaultValue = true, }, new ConfigurationBool(CFG_UPLOAD,"Allow upload") { - Tooltip ="Allow upload of files and folders." + Tooltip = "Allow upload of files and folders." }, new ConfigurationBool(CFG_RENAME,"Allow rename") { - Tooltip ="Allow raname of server files and folders." + Tooltip = "Allow raname of server files and folders." }, new ConfigurationBool(CFG_DELETE,"Allow delete") { - Tooltip ="Allow delete files and folders." + Tooltip = "Allow delete files and folders." }, new ConfigurationBool(CFG_EXECUTE,"Allow execute") { - Tooltip ="Allow application execution on server." + Tooltip = "Allow application execution on server." }, - new ConfigurationMessage(ConfigurationMessage.MessageType.WARNING,"WARNING: Sunfish is exeuted as elevated process, any antion and process started by sunfish will be also elevated.") + new ConfigurationMessage(ConfigurationMessage.MessageType.WARNING,"WARNING: Sunfish is executed as elevated process, any anction or process started by sunfish will be also elevated.") }, Advanced = AdvancedEditing }; diff --git a/Sunfish/Sunfish/Sunfish.csproj b/Sunfish/Sunfish/Sunfish.csproj index 4a046e1..22e470c 100644 --- a/Sunfish/Sunfish/Sunfish.csproj +++ b/Sunfish/Sunfish/Sunfish.csproj @@ -170,7 +170,6 @@ -