diff --git a/ModularToolManger/DefaultTools/CommandLine.cs b/ModularToolManger/DefaultTools/CommandLine.cs index 1a71d1f..22df9e9 100644 --- a/ModularToolManger/DefaultTools/CommandLine.cs +++ b/ModularToolManger/DefaultTools/CommandLine.cs @@ -15,78 +15,27 @@ public class Commandline : IFunction { public bool Active { get; set; } - public string Author - { - get - { - return "Simon Aberle"; - } - } + public string Author => "Simon Aberle"; private PluginContext _context; - public PluginContext context - { - get - { - return _context; - } - } + public PluginContext context => _context; - public string Description - { - get - { - return "Create a function performed by the commandline in Windows"; - } - } + public string Description => "Create a function performed by the commandline in Windows"; - public string DisplayName - { - get - { - return "Windows commandline"; - } - } + public string DisplayName => "Windows commandline"; private Dictionary _fileEndings; - public Dictionary FileEndings - { - get - { - return _fileEndings; - } - } + public Dictionary FileEndings => _fileEndings; private bool _initialized; - public bool initialized - { - get - { - return _initialized; - } - } + public bool initialized => _initialized; - public string UniqueName - { - get - { - return "WindowsCommandLine"; - } - } + public string UniqueName => "WindowsCommandLine"; - public Version Version - { - get - { - return new Version(1, 0, 0, 0); - } - } + public Version Version => new Version(1, 0, 0, 0); private Module _comModule; - public Module ComModule - { - get => _comModule; - } + public Module ComModule => _comModule; PluginSettings _settings; PluginSettings ISettingPlugin.Settings => _settings; @@ -121,8 +70,10 @@ public bool Load() public bool PerformeAction(PluginContext context) { if (context.GetType() != typeof(FunctionContext)) + { return false; - + } + FunctionContext CurrentContext = (FunctionContext)context; Process process = new Process(); diff --git a/ModularToolManger/DefaultTools/LinkOpener.cs b/ModularToolManger/DefaultTools/LinkOpener.cs index cb910af..40548f1 100644 --- a/ModularToolManger/DefaultTools/LinkOpener.cs +++ b/ModularToolManger/DefaultTools/LinkOpener.cs @@ -15,78 +15,27 @@ public class Shortcut : IFunction { public bool Active { get; set; } - public string Author - { - get - { - return "Simon Aberle"; - } - } + public string Author => "Simon Aberle"; private PluginContext _context; - public PluginContext context - { - get - { - return _context; - } - } + public PluginContext context => _context; - public string Description - { - get - { - return "Open a windows shortcut"; - } - } + public string Description => "Open a windows shortcut"; - public string DisplayName - { - get - { - return "Windows shortcut"; - } - } + public string DisplayName => "Windows shortcut"; private Dictionary _fileEndings; - public Dictionary FileEndings - { - get - { - return _fileEndings; - } - } + public Dictionary FileEndings => _fileEndings; private bool _initialized; - public bool initialized - { - get - { - return _initialized; - } - } + public bool initialized => _initialized; - public string UniqueName - { - get - { - return "Shortcut"; - } - } + public string UniqueName => "Shortcut"; - public Version Version - { - get - { - return new Version(1, 0, 0, 0); - } - } + public Version Version => new Version(1, 0, 0, 0); private Module _comModule; - public Module ComModule - { - get => _comModule; - } + public Module ComModule => _comModule; PluginSettings _settings; @@ -123,7 +72,7 @@ public bool PerformeAction(PluginContext context) return false; FunctionContext CurrentContext = (FunctionContext)context; - Process process = new Process(); ; + Process process = new Process(); process.StartInfo.FileName = CurrentContext.FilePath; process.StartInfo.WorkingDirectory = (new FileInfo(CurrentContext.FilePath)).DirectoryName; try @@ -134,8 +83,6 @@ public bool PerformeAction(PluginContext context) { _comModule.SendMessage("log", ex.Message); } - - return true; } diff --git a/ModularToolManger/JSONSettings/JSON/SettingJSON.cs b/ModularToolManger/JSONSettings/JSON/SettingJSON.cs index e079343..c654cd9 100644 --- a/ModularToolManger/JSONSettings/JSON/SettingJSON.cs +++ b/ModularToolManger/JSONSettings/JSON/SettingJSON.cs @@ -18,23 +18,27 @@ public SettingJSON() public bool AddNew(string Name) { if (Contained(Name)) + { return false; + } nodes.Add(new SettingsNode(Name)); return true; } public bool AddValue(string Name, string Key, object Value) { - SettingsNode node = getNode(Name); + SettingsNode node = GetNode(Name); if (node == null) + { return false; + } node.AddOrChangeKeyValue(Key, Value); return true; } public string GetValue(string Name, string Key, out SettingsType type) { - SettingsNode node = getNode(Name); + SettingsNode node = GetNode(Name); if (node == null) { type = SettingsType.Error; @@ -44,12 +48,14 @@ public string GetValue(string Name, string Key, out SettingsType type) return Value; } - private SettingsNode getNode(string Name) + private SettingsNode GetNode(string Name) { foreach (SettingsNode node in nodes) { if (node.Name == Name) + { return node; + } } return null; } @@ -59,7 +65,10 @@ private bool Contained(string name) foreach (SettingsNode node in nodes) { if (node.Name == name) + { return true; + } + } return false; } diff --git a/ModularToolManger/JSONSettings/JSON/SettingsNode.cs b/ModularToolManger/JSONSettings/JSON/SettingsNode.cs index 555fe64..f0579af 100644 --- a/ModularToolManger/JSONSettings/JSON/SettingsNode.cs +++ b/ModularToolManger/JSONSettings/JSON/SettingsNode.cs @@ -8,26 +8,24 @@ namespace JSONSettings { public class SettingsNode { - public string Name; - public List Settings; + readonly string _name; + public string Name => _name; + + readonly List _settings; + public List Settings => _settings; public SettingsNode() { - init(); + _settings = new List(); } public SettingsNode(string name) { - init(); - Name = name; - } - - private void init() - { - Settings = new List(); + _settings = new List(); + _name = name; } - private bool AddKeyValue(string key, object Value, SettingsType valueType = SettingsType.String) + private void AddKeyValue(string key, object Value, SettingsType valueType = SettingsType.String) { if (KeyContained(key)) { @@ -42,19 +40,18 @@ private bool AddKeyValue(string key, object Value, SettingsType valueType = Sett } else { - Settings.Add(new KeyValue() + Settings.Add(new KeyValue { Key = key, Value = Value.ToString(), ValueType = valueType, }); } - - return true; } + public bool AddOrChangeKeyValue(string key, object Value) { - SettingsType type = SettingsType.String; + SettingsType type; TypeCode code = Type.GetTypeCode(Value.GetType()); switch (code) { @@ -69,6 +66,7 @@ public bool AddOrChangeKeyValue(string key, object Value) type = SettingsType.Float; break; default: + type = SettingsType.String; break; } if (type != SettingsType.Error) @@ -105,14 +103,11 @@ private bool KeyContained(string key) foreach (KeyValue pair in Settings) { if (pair.Key == key) + { return true; + } } return false; } - - internal void GetValue(string Name) - { - - } } } diff --git a/ModularToolManger/JSONSettings/Settings.cs b/ModularToolManger/JSONSettings/Settings.cs index c0321a2..e67e973 100644 --- a/ModularToolManger/JSONSettings/Settings.cs +++ b/ModularToolManger/JSONSettings/Settings.cs @@ -14,7 +14,7 @@ public class Settings private SettingJSON _settings; private string _defaultApp; public string DefaultApp => _defaultApp; - private string _saveFile; + readonly string _saveFile; @@ -29,7 +29,10 @@ public void AddNewField(string Name) { _settings.AddNew(Name); if (_settings.nodes.Count == 1) + { _defaultApp = Name; + } + } public void AddOrChangeKeyValue(string Name, string Key, object Value) @@ -43,9 +46,8 @@ public void AddOrChangeKeyValue(string Key, object Value) public bool GetBoolValue(string Name, string key) { - SettingsType type; bool returnBool = false; ; - string value = _settings.GetValue(Name, key, out type); + string value = _settings.GetValue(Name, key, out SettingsType type); if (type == SettingsType.Bool) { bool.TryParse(value, out returnBool); @@ -59,11 +61,12 @@ public bool GetBoolValue(string key) public int GetIntValue(string Name, string key) { - SettingsType type; int returnInt = -1; - string value = _settings.GetValue(Name, key, out type); + string value = _settings.GetValue(Name, key, out SettingsType type); if (type == SettingsType.Int) + { int.TryParse(value, out returnInt); + } return returnInt; } public int GetIntValue(string key) @@ -73,11 +76,12 @@ public int GetIntValue(string key) public float GetFloatValue(string Name, string key) { - SettingsType type; float returnFloat = -1; - string value = _settings.GetValue(Name, key, out type); + string value = _settings.GetValue(Name, key, out SettingsType type); if (type == SettingsType.Float) + { float.TryParse(value, out returnFloat); + } return returnFloat; } public float GetFloatValue(string key) @@ -89,7 +93,9 @@ public string GetValue(string Name, string key, out SettingsType type) { string returnString = _settings.GetValue(Name, key, out type); if (type == SettingsType.Error) + { return ""; + } return returnString; } @@ -100,10 +106,12 @@ public string GetValue(string key, out SettingsType type) public string GetValue(string Name, string key) { - SettingsType type; - string returnString = _settings.GetValue(Name, key, out type); + string returnString = _settings.GetValue(Name, key, out SettingsType type); if (type == SettingsType.Error) + { return ""; + } + return returnString; } public string GetValue(string key) @@ -113,15 +121,23 @@ public string GetValue(string key) - - public void Save(bool compressed = false ) + public void Save() + { + Save(false); + } + public void Save(bool compressed) { Formatting format = Formatting.Indented; if (compressed) + { format = Formatting.None; + } FileInfo FI = new FileInfo(_saveFile); if (!Directory.Exists(FI.DirectoryName)) + { Directory.CreateDirectory(FI.DirectoryName); + } + string settings = JsonConvert.SerializeObject(_settings, format); using (StreamWriter writer = new StreamWriter(_saveFile)) { @@ -132,7 +148,10 @@ public void Save(bool compressed = false ) private void Load() { if (!File.Exists(_saveFile)) + { return; + } + using (StreamReader reader = new StreamReader(_saveFile)) { string data = reader.ReadToEnd(); @@ -140,7 +159,10 @@ private void Load() { _settings = JsonConvert.DeserializeObject(data); if (_settings.nodes.Count > 0) + { _defaultApp = _settings.nodes[0].Name; + } + } catch (Exception) { diff --git a/ModularToolManger/ModularToolManger/DLL/Newtonsoft.Json.dll b/ModularToolManger/ModularToolManger/DLL/Newtonsoft.Json.dll deleted file mode 100644 index 77a5d89..0000000 Binary files a/ModularToolManger/ModularToolManger/DLL/Newtonsoft.Json.dll and /dev/null differ diff --git a/ModularToolManger/ModularToolManger/Forms/F_NewFunction.cs b/ModularToolManger/ModularToolManger/Forms/F_NewFunction.cs index cea0977..cd22634 100644 --- a/ModularToolManger/ModularToolManger/Forms/F_NewFunction.cs +++ b/ModularToolManger/ModularToolManger/Forms/F_NewFunction.cs @@ -17,33 +17,29 @@ namespace ModularToolManger.Forms { public partial class F_NewFunction : Form { - private Manager _pluginManager; + readonly Manager _pluginManager; private int _endPos; private int _startPos; private Function _returnFunction; - public Function NewFunction - { - get - { - return _returnFunction; - } - } - private bool _editMode; + public Function NewFunction => _returnFunction; + + readonly bool _editMode; private bool _firstOpen; - public F_NewFunction(ref Manager pluginManager, Function _functionToEdit = null) + public F_NewFunction(Manager pluginManager, Function _functionToEdit) : this(pluginManager) + { + _returnFunction = _functionToEdit; + _editMode = true; + } + + public F_NewFunction(Manager pluginManager) { InitializeComponent(); _pluginManager = pluginManager; _startPos = 0; - _returnFunction = _functionToEdit; _editMode = false; - if (_returnFunction != null) - { - _editMode = true; - } _firstOpen = true; } @@ -114,7 +110,9 @@ private void SetupLabels() { Control currentLabel = Labels[i]; if (currentLabel.Width > _startPos) + { _startPos = currentLabel.Width; + } } } @@ -147,7 +145,6 @@ private void FillFields() for (int i = 0; i < F_NewFunction_CB_Type.Items.Count; i++) { IPlugin plugin = _pluginManager.LoadetPlugins[i]; - object CBI = F_NewFunction_CB_Type.Items[i]; if (plugin.UniqueName == _returnFunction.Type) { _selectIndex = i; @@ -248,7 +245,7 @@ private void Default_OK_Click(object sender, EventArgs e) } if (Tag != null && Tag.GetType() == typeof(string)) { - _returnFunction = new Function() + _returnFunction = new Function { ID = Guid.NewGuid().ToString(), Name = F_NewFunction_TB_Name.Text, diff --git a/ModularToolManger/ModularToolManger/Forms/F_Password.cs b/ModularToolManger/ModularToolManger/Forms/F_Password.cs index f4d3698..c9a4502 100644 --- a/ModularToolManger/ModularToolManger/Forms/F_Password.cs +++ b/ModularToolManger/ModularToolManger/Forms/F_Password.cs @@ -31,7 +31,7 @@ private void F_Password_Load(object sender, EventArgs e) SetLanguage(); F_Password_TB_Password.Focus(); - this.DoForEveryControl(typeof(Label), getBiggestLabel); + this.DoForEveryControl(typeof(Label), GetBiggestLabel); SetupTextFields(); Default_OK.Center(this); @@ -42,10 +42,10 @@ private void SetupTextFields() { _textFieldEndPos = F_Password_TB_Password.Location.X + F_Password_TB_Password.Size.Width; - this.DoForEveryControl(typeof(TextBox), setTextFieldSize); + this.DoForEveryControl(typeof(TextBox), SetTextFieldSize); } - private bool setTextFieldSize(Control B) + private bool SetTextFieldSize(Control B) { B.Location = new Point(_biggestLabel, B.Location.Y); B.Size = new Size(_textFieldEndPos - _biggestLabel, B.Size.Height); @@ -53,10 +53,12 @@ private bool setTextFieldSize(Control B) return true; } - private bool getBiggestLabel(Control B) + private bool GetBiggestLabel(Control B) { if (B.Location.X + B.Size.Width > _biggestLabel) + { _biggestLabel = B.Location.X + B.Size.Width; + } return true; } @@ -75,7 +77,10 @@ private void Default_OK_Click(object sender, EventArgs e) private void F_Password_TB_Password_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) + { Default_OK.PerformClick(); + } + } } } diff --git a/ModularToolManger/ModularToolManger/Forms/F_ReportBug.cs b/ModularToolManger/ModularToolManger/Forms/F_ReportBug.cs index d179de8..390ada5 100644 --- a/ModularToolManger/ModularToolManger/Forms/F_ReportBug.cs +++ b/ModularToolManger/ModularToolManger/Forms/F_ReportBug.cs @@ -14,18 +14,22 @@ namespace ModularToolManger.Forms { + //ToDo This need's to use the GitHub issue creation instead of the Bitbucket one public partial class F_ReportBug : Form { private int _biggestLabel; private int _textFieldEndPos; - private Settings _settings; + + readonly Settings _settings; + + readonly HashSet _allowedFiletypes; + readonly int _maxFileSize; + readonly int _allFileSize; private Kind _curKind; private Priority _curPriority; - private HashSet _allowedFiletypes; - private int _maxFileSize; - private int _allFileSize; + public F_ReportBug(Settings settings) { @@ -63,7 +67,7 @@ private void F_ReportBug_Load(object sender, EventArgs e) SetLanguage(); SetupComboBoxes(); - this.DoForEveryControl(typeof(Label), getBiggestLabel); + this.DoForEveryControl(typeof(Label), GetBiggestLabel); SetupTextFields(); this.DoForEveryControl(typeof(Button), SizeButtons); @@ -111,12 +115,12 @@ private void F_ReportBug_LV_Files_DragDrop(object sender, DragEventArgs e) { continue; } - if (getCompleteFileSize() > _allFileSize) + if (GetCompleteFileSize() > _allFileSize) { continue; } - F_ReportBug_LV_Files.Items.Add(new ListViewItem() + F_ReportBug_LV_Files.Items.Add(new ListViewItem { Text = fi.Name, Tag = fi, @@ -125,7 +129,7 @@ private void F_ReportBug_LV_Files_DragDrop(object sender, DragEventArgs e) } - private HashSet getFiles() + private HashSet GetFiles() { HashSet files = new HashSet(); foreach (ListViewItem item in F_ReportBug_LV_Files.Items) @@ -140,7 +144,7 @@ private HashSet getFiles() return files; } - private int getCompleteFileSize() + private int GetCompleteFileSize() { int Return = 0; foreach (ListViewItem item in F_ReportBug_LV_Files.Items) @@ -192,7 +196,7 @@ private void SetupPriorityComboBox() F_Report_Bug_CB_Priority.SelectedIndex = 0; } - private bool getBiggestLabel(Control B) + private bool GetBiggestLabel(Control B) { if (B.Location.X + B.Size.Width > _biggestLabel) { @@ -205,12 +209,12 @@ private void SetupTextFields() { _textFieldEndPos = F_ReportBug_TB_Title.Location.X + F_ReportBug_TB_Title.Size.Width; - this.DoForEveryControl(typeof(TextBox), setTextFieldSize); - this.DoForEveryControl(typeof(ListView), setTextFieldSize); - this.DoForEveryControl(typeof(ComboBox), setTextFieldSize); + this.DoForEveryControl(typeof(TextBox), SetTextFieldSize); + this.DoForEveryControl(typeof(ListView), SetTextFieldSize); + this.DoForEveryControl(typeof(ComboBox), SetTextFieldSize); } - private bool setTextFieldSize(Control B) + private bool SetTextFieldSize(Control B) { B.Location = new Point(_biggestLabel, B.Location.Y); B.Size = new Size(_textFieldEndPos - _biggestLabel, B.Size.Height); @@ -241,7 +245,9 @@ private void Default_Send_Click(object sender, EventArgs e) OAuthEntry.ShowDialog(); if (!OAuthEntry.GoodToGO) + { return; + } key = _settings.GetValue("OauthKey"); secret = _settings.GetValue("OAuthSecret"); } @@ -268,12 +274,14 @@ private void Default_Send_Click(object sender, EventArgs e) Issue issue = new Issue(repository, authentication.ResponseData); - HashSet files = getFiles(); + HashSet files = GetFiles(); List uploadFiles = new List(); foreach (FileInfo fi in files) { if (!File.Exists(fi.FullName)) + { continue; + } uploadFiles.Add(fi.FullName); } @@ -333,7 +341,6 @@ private void CMS_LV_Files_Opening(object sender, CancelEventArgs e) { CMS_LV_Files.Visible = false; e.Cancel = true; - return; } } diff --git a/ModularToolManger/ModularToolManger/Forms/F_Settings.Designer.cs b/ModularToolManger/ModularToolManger/Forms/F_Settings.Designer.cs index 95cf824..bd29b91 100644 --- a/ModularToolManger/ModularToolManger/Forms/F_Settings.Designer.cs +++ b/ModularToolManger/ModularToolManger/Forms/F_Settings.Designer.cs @@ -147,7 +147,6 @@ private void InitializeComponent() this.F_Settings_CB_KeepOnTop.Tag = "KeepOnTop"; this.F_Settings_CB_KeepOnTop.Text = "F_Settings_CB_KeepOnTop"; this.F_Settings_CB_KeepOnTop.UseVisualStyleBackColor = true; - this.F_Settings_CB_KeepOnTop.CheckedChanged += new System.EventHandler(this.F_Settings_CB_KeepOnTop_CheckedChanged); // // Default_OK // diff --git a/ModularToolManger/ModularToolManger/Forms/F_Settings.cs b/ModularToolManger/ModularToolManger/Forms/F_Settings.cs index 9b000f3..857f10a 100644 --- a/ModularToolManger/ModularToolManger/Forms/F_Settings.cs +++ b/ModularToolManger/ModularToolManger/Forms/F_Settings.cs @@ -18,10 +18,11 @@ namespace ModularToolManger.Forms { public partial class F_Settings : Form { - private Settings _settings; - private List _availablePlugins; + readonly Settings _settings; + readonly List _availablePlugins; public Settings Settings => _settings; - public bool Save; + private bool _save; + public bool Save => _save; private bool _starting; private int yStart; @@ -30,12 +31,15 @@ public partial class F_Settings : Form private int curY; - public F_Settings(Settings settings, List plugins = null) + public F_Settings(Settings settings, List plugins) : this(settings) { - _settings = settings; _availablePlugins = plugins; + } + public F_Settings(Settings settings) + { + _settings = settings; InitializeComponent(); - Save = false; + _save = false; _starting = true; } @@ -69,13 +73,16 @@ private bool SizeButtons(Control C) private void SetupTabs() { if (_availablePlugins == null) + { return; + } + for (int i = 0; i < _availablePlugins.Count; i++) { IPlugin plugin = _availablePlugins[i]; TabPage basicDesign = tabControl1.TabPages[0]; - TabPage newPage = new TabPage() + TabPage newPage = new TabPage { BackColor = basicDesign.BackColor, BackgroundImage = basicDesign.BackgroundImage, @@ -86,27 +93,24 @@ private void SetupTabs() newPage.Name = plugin.UniqueName; newPage.Tag = "Added"; - try - { - setupTabPage(newPage, (IFunction)plugin); - } - catch (Exception) - { - } - + + SetupTabPage(newPage, (IFunction)plugin); if (newPage.Controls.Count > 0) + { tabControl1.TabPages.Add(newPage); + } + } } - private void setupTabPage(Control Tab, IFunction curFunction) + private void SetupTabPage(Control Tab, IFunction curFunction) { foreach (IPluginSetting curSettings in curFunction.Settings.AllSettings) { if (curSettings.objectType == typeof(bool)) { - CheckBox CB = new CheckBox() + CheckBox CB = new CheckBox { Text = curSettings.DisplayName, Tag = curSettings.Key, @@ -118,7 +122,7 @@ private void setupTabPage(Control Tab, IFunction curFunction) } else { - Tab.Controls.Add(new Label() + Tab.Controls.Add(new Label { Text = curSettings.Key, }); @@ -133,25 +137,24 @@ private void SetupEntries() this.DoForEveryControl((Control TP) => { if (TP.GetType() == typeof(TabPage)) + { TP.DoForEveryControl((Control c) => { string Name = _settings.DefaultApp; if (c.GetType() == typeof(Label)) + { return true; + } + if (TP.Tag.ToString() == "Added") + { Name = TP.Name; + } IPlugin curPlugin = GetPluginByName(Name); IFunction curFunction = null; if (curPlugin != null) { - - try - { - curFunction = (IFunction)curPlugin; - } - catch (Exception) - { - } + curFunction = (IFunction)curPlugin; } string SettingsKey = c.Tag.ToString(); @@ -161,7 +164,9 @@ private void SetupEntries() cb.Checked = _settings.GetBoolValue(Name, SettingsKey); if (curFunction != null) + { curFunction.Settings.UpdateValue(SettingsKey, cb.Checked); + } } if (c.GetType() == typeof(TrackBar)) { @@ -171,7 +176,10 @@ private void SetupEntries() tbar.Value = loadetValue; } return true; + }); + } + return true; }); } @@ -181,16 +189,14 @@ private IPlugin GetPluginByName(string uniqueName) foreach (IPlugin plugin in _availablePlugins) { if (plugin.UniqueName == uniqueName) + { return plugin; + } + } return null; } - private void F_Settings_CB_KeepOnTop_CheckedChanged(object sender, EventArgs e) - { - - } - private void Default_OK_Click(object sender, EventArgs e) { this.DoForEveryControl((Control TP) => { @@ -203,12 +209,15 @@ private void Default_OK_Click(object sender, EventArgs e) if (TP.Tag.ToString() == "Added") { Name = TP.Name; - updatePlugins(Name, (TabPage)TP); + UpdatePlugins(Name, (TabPage)TP); } string SettingsName = c.Tag.ToString(); if (SettingsName == "") + { return false; + } + if (c.GetType() == typeof(CheckBox)) { @@ -224,14 +233,14 @@ private void Default_OK_Click(object sender, EventArgs e) }); return true; }); - Save = true; + _save = true; this.Close(); } - private void updatePlugins(string pluginName, TabPage page) + private void UpdatePlugins(string pluginName, TabPage page) { page.DoForEveryControl((Control c) => { @@ -264,29 +273,20 @@ private void updatePlugins(string pluginName, TabPage page) private void F_Settings_CB_AutoStart_CheckedChanged(object sender, EventArgs e) { - //Disabled to prevent virus warning - //RegistryKey AutostartKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true); - //if (F_Settings_CB_AutoStart.Checked) - //{ - // AutostartKey.SetValue("ToolManagerAutoStart", Application.ExecutablePath.ToString()); - // AutostartKey.Close(); - //} - //else - //{ - // AutostartKey.DeleteValue("ToolManagerAutoStart"); - //} - - //compromise solution if (_starting) return; string TargetFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup); string Name = "Tool Manager.url"; string ShortcutFile = $"{TargetFolder}\\{Name}"; if (F_Settings_CB_AutoStart.Checked) + { CreateShortcut(ShortcutFile); + } else + { DeleteShortcut(ShortcutFile); - + } + } private void CreateShortcut(string ShortcutFile) @@ -306,7 +306,10 @@ private void CreateShortcut(string ShortcutFile) private void DeleteShortcut(string ShortcutFile) { if (File.Exists(ShortcutFile)) - File.Delete(ShortcutFile); + { + File.Delete(ShortcutFile); + } + } private void Default_Abort_Click(object sender, EventArgs e) diff --git a/ModularToolManger/ModularToolManger/Forms/F_ToolManager.Designer.cs b/ModularToolManger/ModularToolManger/Forms/F_ToolManager.Designer.cs index 5f26be8..59999ea 100644 --- a/ModularToolManger/ModularToolManger/Forms/F_ToolManager.Designer.cs +++ b/ModularToolManger/ModularToolManger/Forms/F_ToolManager.Designer.cs @@ -108,7 +108,7 @@ private void InitializeComponent() this.Default_Close.Name = "Default_Close"; this.Default_Close.Size = new System.Drawing.Size(232, 22); this.Default_Close.Text = "Default_Close"; - this.Default_Close.Click += new System.EventHandler(this.defaultCloseToolStripMenuItem_Click); + this.Default_Close.Click += new System.EventHandler(this.DefaultCloseToolStripMenuItem_Click); // // F_ToolManager_ReportBug // @@ -171,7 +171,7 @@ private void InitializeComponent() this.Default_Show.Name = "Default_Show"; this.Default_Show.Size = new System.Drawing.Size(265, 22); this.Default_Show.Text = "Default_Show"; - this.Default_Show.Click += new System.EventHandler(this.defaultShowToolStripMenuItem_Click); + this.Default_Show.Click += new System.EventHandler(this.DefaultShowToolStripMenuItem_Click); // // F_ToolManager_NI_Taskbar_Buttons // diff --git a/ModularToolManger/ModularToolManger/Forms/F_ToolManager.cs b/ModularToolManger/ModularToolManger/Forms/F_ToolManager.cs index b3648af..2c205df 100644 --- a/ModularToolManger/ModularToolManger/Forms/F_ToolManager.cs +++ b/ModularToolManger/ModularToolManger/Forms/F_ToolManager.cs @@ -19,9 +19,11 @@ public partial class F_ToolManager : Form { private Manager _pluginManager; private FunctionsManager _functionManager; - private int _startOffset = 25; + readonly int _startOffset; + readonly int _maxHeight; + private int _baseScrollValue; - private int _maxHeight; + private int _minWidth; private Point _location; private bool _forceClose; @@ -32,7 +34,6 @@ public partial class F_ToolManager : Form private string _functionsPath; - //private int _lastContextListButton; private Settings _settingsContainer; private LanguageCom _languageConnector; @@ -41,13 +42,12 @@ public partial class F_ToolManager : Form public F_ToolManager() { InitializeComponent(); + _startOffset = 25; _hidden = false; _forceClose = false; _searchbarAdded = false; KeyPreview = true; - //_lastContextListButton = 0; - Default_Show.Visible = _hidden; _minWidth = this.Size.Width; @@ -87,7 +87,7 @@ private void SetupPlugins() private List LoadPlugins() { _pluginManager.Initialize(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName + @"\Modules"); - _pluginManager.Error += _pluginManager_Error; + _pluginManager.Error += PluginManager_Error; _pluginManager.LoadPlugins(); List allowedTypes = new List(); @@ -109,7 +109,7 @@ private void LoadFunctions(List allowedTypes) _functionManager = new FunctionsManager(_functionsPath + "functions.json", allowedTypes); _functionManager.Load(); } - private void _pluginManager_Error(object sender, ErrorData e) + private void PluginManager_Error(object sender, ErrorData e) { CentralLogging.AppDebugLogger.Log(e.Message, Logging.LogLevel.Error); CentralLogging.AppDebugLogger.Log(e.ErrorException.Message, Logging.LogLevel.Error); @@ -127,18 +127,24 @@ private void Form1_Load(object sender, EventArgs e) SetupButtons(); - setScrollSpeed(); + SetScrollSpeed(); F_ToolManager_Hide.Visible = _settingsContainer.GetBoolValue("Borderless"); } - private void setScrollSpeed() + private void SetScrollSpeed() { _baseScrollValue = 3; _baseScrollValue = _settingsContainer.GetIntValue("ScrollSpeed"); if (_baseScrollValue < F_ToolManager_ScrollBar.Minimum) + { _baseScrollValue = F_ToolManager_ScrollBar.Minimum; + } + if (_baseScrollValue > F_ToolManager_ScrollBar.Maximum) + { _baseScrollValue = F_ToolManager_ScrollBar.Maximum; + } + } private void MoveToPosition() @@ -161,45 +167,42 @@ private void SetupSettingsForPlugins() for (int i = 0; i < _pluginManager.PluginCount; i++) { _settingsContainer.AddNewField(_pluginManager.LoadetPlugins[i].UniqueName); - try - { - IFunction function = (IFunction)_pluginManager.LoadetPlugins[i]; + IFunction function = (IFunction)_pluginManager.LoadetPlugins[i]; - foreach (IPluginSetting setting in function.Settings.AllSettings) + foreach (IPluginSetting setting in function.Settings.AllSettings) + { + SettingsType type = SettingsType.Error; + string curSettings = _settingsContainer.GetValue(function.UniqueName, setting.Key, out type); + switch (type) { - SettingsType type = SettingsType.Error; - string curSettings = _settingsContainer.GetValue(function.UniqueName, setting.Key, out type); - switch (type) - { - case SettingsType.String: - function.Settings.UpdateValue(setting.Key, curSettings); - break; - case SettingsType.Bool: - bool Bvalue = false; - if (bool.TryParse(curSettings, out Bvalue)) - function.Settings.UpdateValue(setting.Key, Bvalue); - break; - case SettingsType.Int: - int Ivalue = 0; - if (int.TryParse(curSettings, out Ivalue)) - function.Settings.UpdateValue(setting.Key, Ivalue); - break; - case SettingsType.Float: - float Fvalue = 0; - if (float.TryParse(curSettings, out Fvalue)) - function.Settings.UpdateValue(setting.Key, Fvalue); - break; - case SettingsType.Error: - break; - default: - break; - } - // + case SettingsType.String: + function.Settings.UpdateValue(setting.Key, curSettings); + break; + case SettingsType.Bool: + bool Bvalue = false; + if (bool.TryParse(curSettings, out Bvalue)) + { + function.Settings.UpdateValue(setting.Key, Bvalue); + } + break; + case SettingsType.Int: + int Ivalue = 0; + if (int.TryParse(curSettings, out Ivalue)) + { + function.Settings.UpdateValue(setting.Key, Ivalue); + } + break; + case SettingsType.Float: + float Fvalue = 0; + if (float.TryParse(curSettings, out Fvalue)) + { + function.Settings.UpdateValue(setting.Key, Fvalue); + } + break; + case SettingsType.Error: + default: + break; } - - } - catch (Exception) - { } } } @@ -232,19 +235,23 @@ private void SetupButtons(string filter = ".*") { continue; } - Button newButton = createButton(currentFunction); + Button newButton = CreateButton(currentFunction); newButton.Location = new Point(0, _startOffset + buttonsAdded * 25 + newButton.Size.Height); this.Controls.Add(newButton); lastButton = newButton; buttonsAdded++; if (currentFunction.ShowInNotification) - addNewToolStripMenuItem(currentFunction); - + { + AddNewToolStripMenuItem(currentFunction); + } + } if (F_ToolManager_NI_Taskbar_Buttons.DropDownItems.Count > 0) + { F_ToolManager_NI_Taskbar_Buttons.Visible = true; + } } List buttons = this.GetAllControls(typeof(Button)); @@ -256,7 +263,7 @@ private void SetupButtons(string filter = ".*") CalculateFormSize(lastButton, buttons); } - private void addNewToolStripMenuItem(Function currentFunction) + private void AddNewToolStripMenuItem(Function currentFunction) { ToolStripMenuItem newItem = new ToolStripMenuItem(currentFunction.Name) { @@ -268,9 +275,9 @@ private void addNewToolStripMenuItem(Function currentFunction) F_ToolManager_NI_Taskbar_Buttons.DropDownItems.Add(newItem); } - private Button createButton(Function currentFunction) + private Button CreateButton(Function currentFunction) { - Button newButton = new Button() + Button newButton = new Button { Name = currentFunction.ID, Text = currentFunction.Name, @@ -291,7 +298,9 @@ private void CalculateFormSize(Button lastButton, List buttons) int newWidth = 0; int newHeight = 0; if (lastButton != null) + { newHeight = lastButton.Location.Y + lastButton.Size.Height + _startOffset * 2; + } if (newHeight > _maxHeight) { F_ToolManager_ScrollBar.Maximum = newHeight - _maxHeight; @@ -302,11 +311,17 @@ private void CalculateFormSize(Button lastButton, List buttons) for (int i = 0; i < buttons.Count; i++) { if (buttons[i].Size.Width > BiggestValue) + { BiggestValue = buttons[i].Size.Width; + } + } newWidth = BiggestValue; if (newWidth < _minWidth) + { newWidth = _minWidth; + } + this.Size = new Size(newWidth, newHeight); this.DoForEveryControl(typeof(Button), CenterButton); @@ -323,7 +338,10 @@ private bool CenterButton(Control B) private bool DeleteButton(Control B) { if (B.GetType() != typeof(Button)) + { return false; + } + this.Controls.Remove(((Button)B)); return true; } @@ -334,7 +352,7 @@ private bool OffsetButton(Control B) return true; } - private Button GetButtonFromTSMI(ToolStripMenuItem tsmi) + private Button GetButtonFromTsmi(ToolStripMenuItem tsmi) { if (tsmi != null) { @@ -343,7 +361,10 @@ private Button GetButtonFromTSMI(ToolStripMenuItem tsmi) { Control Source = ((ContextMenuStrip)owner).SourceControl; if (Source != null && Source.GetType() == typeof(Button)) + { return (Button)Source; + } + } } return null; @@ -373,9 +394,15 @@ private void NewItem_Click(object sender, EventArgs e) Function func = (Function)TSMI.Tag; IPlugin currentPlugin = _pluginManager.GetPluginByName(func.Type); if (currentPlugin == null) + { return; + } + if (currentPlugin.ContainsInterface(typeof(IFunction))) + { func.PerformeAction((IFunction)currentPlugin); + } + } } } @@ -386,14 +413,14 @@ private void F_ToolManager_Settings_Click(object sender, EventArgs e) F_ToolManager_NI_Taskbar_Close.Enabled = false; settingsForm.ShowDialog(); if (settingsForm.Save) + { _settingsContainer = settingsForm.Settings; + } + Show(); _settingsContainer.Save(); - if (_settingsContainer.GetBoolValue("KeepOnTop")) - TopMost = true; - else - TopMost = false; + CheckForTopmost(); ShowInTaskbar = (!_settingsContainer.GetBoolValue("HideInTaskbar")); F_ToolManager_NI_Taskbar_Close.Enabled = true; @@ -404,8 +431,21 @@ private void F_ToolManager_Settings_Click(object sender, EventArgs e) else FormBorderStyle = FormBorderStyle.Fixed3D; - setScrollSpeed(); + SetScrollSpeed(); } + + private void CheckForTopmost() + { + if (_settingsContainer.GetBoolValue("KeepOnTop")) + { + TopMost = true; + } + else + { + TopMost = false; + } + } + private void F_ToolManager_Shown(object sender, EventArgs e) { if (_settingsContainer.GetBoolValue("StartMinimized")) @@ -419,22 +459,30 @@ private void F_ToolManager_Shown(object sender, EventArgs e) private void F_ToolManager_MouseWheel(object sender, MouseEventArgs e) { if (!F_ToolManager_ScrollBar.Visible) + { return; + } + int Test = e.Delta < 0 ? _baseScrollValue : -_baseScrollValue; Test = F_ToolManager_ScrollBar.Value + Test; if (Test < 0) + { return; + } + if (Test > F_ToolManager_ScrollBar.Maximum) + { return; + } _newValue = Test; this.DoForEveryControl(typeof(Button), OffsetButton); F_ToolManager_ScrollBar.Value = Test; } - private void defaultCloseToolStripMenuItem_Click(object sender, EventArgs e) + private void DefaultCloseToolStripMenuItem_Click(object sender, EventArgs e) { _forceClose = true; this.Close(); @@ -449,10 +497,15 @@ private void F_ToolManager_Click(object sender, EventArgs e) Function func = (Function)B.Tag; IPlugin currentPlugin = _pluginManager.GetPluginByName(func.Type); if (currentPlugin == null) + { return; + } + if (currentPlugin.ContainsInterface(typeof(IFunction))) + { func.PerformeAction((IFunction)currentPlugin); - + } + if (_searchbarAdded && _settingsContainer.GetBoolValue("DisableSearchByButton")) { List textBoxes = this.GetAllControls(typeof(TextBox)); @@ -481,7 +534,7 @@ private void F_ToolManager_Langauge_Click(object sender, EventArgs e) } private void F_ToolManager_NewFunction_Click(object sender, EventArgs e) { - F_NewFunction NewFunction = new F_NewFunction(ref _pluginManager); + F_NewFunction NewFunction = new F_NewFunction(_pluginManager); Hide(); F_ToolManager_NI_Taskbar_Close.Enabled = false; NewFunction.ShowDialog(); @@ -498,11 +551,14 @@ private void F_ToolManager_NewFunction_Click(object sender, EventArgs e) private void F_ToolManager_ButtonContext_Edit_Click(object sender, EventArgs e) { if (sender.GetType() != typeof(ToolStripMenuItem)) + { return; + } + - Button B = GetButtonFromTSMI((ToolStripMenuItem)sender); + Button B = GetButtonFromTsmi((ToolStripMenuItem)sender); Function currentFunction = GetFunctionFromButton(B); - F_NewFunction EditFunction = new F_NewFunction(ref _pluginManager, currentFunction); + F_NewFunction EditFunction = new F_NewFunction(_pluginManager, currentFunction); this.Hide(); EditFunction.ShowDialog(); if (EditFunction.NewFunction != null) @@ -524,7 +580,7 @@ private void F_ToolManager_ButtonContext_Delete_Click(object sender, EventArgs e if (sender.GetType() != typeof(ToolStripMenuItem)) return; - Button B = GetButtonFromTSMI((ToolStripMenuItem)sender); + Button B = GetButtonFromTsmi((ToolStripMenuItem)sender); _functionManager.DeleteFunction(GetFunctionFromButton(B)); SetupButtons(); } @@ -549,7 +605,10 @@ private void F_ToolManager_NI_Taskliste_Click(object sender, EventArgs e) { MouseEventArgs NewE = (MouseEventArgs)e; if (NewE.Button == MouseButtons.Right) + { return; + } + } if (_hidden) { @@ -557,27 +616,24 @@ private void F_ToolManager_NI_Taskliste_Click(object sender, EventArgs e) this.MoveToPosition(); this.Show(); Default_Show.Visible = _hidden; - - if (_settingsContainer.GetBoolValue("KeepOnTop")) - TopMost = true; - else - TopMost = false; + CheckForTopmost(); } else { TopMost = true; if (!_settingsContainer.GetBoolValue("KeepOnTop")) + { TopMost = false; + } + } - - } private void F_ToolManager_NI_Taskliste_Close_Click(object sender, EventArgs e) { _forceClose = true; this.Close(); } - private void defaultShowToolStripMenuItem_Click(object sender, EventArgs e) + private void DefaultShowToolStripMenuItem_Click(object sender, EventArgs e) { F_ToolManager_NI_Taskliste_Click(sender, e); } @@ -586,15 +642,16 @@ protected override void WndProc(ref Message message) { const int WM_SYSCOMMAND = 0x0112; const int SC_MOVE = 0xF010; - - switch (message.Msg) + + if (message.Msg == WM_SYSCOMMAND) { - case WM_SYSCOMMAND: - int command = message.WParam.ToInt32() & 0xfff0; - if (command == SC_MOVE) - return; - break; + int command = message.WParam.ToInt32() & 0xfff0; + if (command == SC_MOVE) + { + return; + } } + base.WndProc(ref message); } @@ -619,13 +676,14 @@ private void F_ToolManager_KeyPress(object sender, KeyPressEventArgs e) TextBox searchBox; if (!_searchbarAdded) { - searchBox = new TextBox(); - - searchBox.Location = new Point(0, F_MainMenuStrip.Height); - searchBox.Size = new Size(Width, 21); - searchBox.Tag = "SearchBox"; - searchBox.Text = e.KeyChar.ToString(); - searchBox.TabIndex = 999; + searchBox = new TextBox + { + Location = new Point(0, F_MainMenuStrip.Height), + Size = new Size(Width, 21), + Tag = "SearchBox", + Text = e.KeyChar.ToString(), + TabIndex = 999 + }; searchBox.KeyPress += SearchBox_KeyPress; Controls.Add(searchBox); @@ -634,10 +692,10 @@ private void F_ToolManager_KeyPress(object sender, KeyPressEventArgs e) searchBox.Focus(); int textLenght = searchBox.Text.Length; searchBox.Select(textLenght, textLenght); - SetupButtons(buildRegex(searchBox.Text)); + SetupButtons(BuildRegex(searchBox.Text)); } } - private TextBox getSearchboxBySender(object sender) + private TextBox GetSearchboxBySender(object sender) { if (sender.GetType() == typeof(TextBox)) { @@ -649,7 +707,7 @@ private TextBox getSearchboxBySender(object sender) } return null; } - private string buildRegex(string value) + private string BuildRegex(string value) { value = value.Replace("?", "."); value = value.Replace("*", ".*"); @@ -662,17 +720,17 @@ private void SearchBox_KeyPress(object sender, KeyPressEventArgs e) RemoveSearchbar(sender); return; } - TextBox curTextBox = getSearchboxBySender(sender); + TextBox curTextBox = GetSearchboxBySender(sender); if (curTextBox == null) { return; } - SetupButtons(buildRegex(curTextBox.Text)); + SetupButtons(BuildRegex(curTextBox.Text)); } private void RemoveSearchbar(object sender) { - TextBox curTextBox = getSearchboxBySender(sender); + TextBox curTextBox = GetSearchboxBySender(sender); if (curTextBox == null) { return; diff --git a/ModularToolManger/ModularToolManger/ModularToolManger.csproj b/ModularToolManger/ModularToolManger/ModularToolManger.csproj index a99814d..8b6809a 100644 --- a/ModularToolManger/ModularToolManger/ModularToolManger.csproj +++ b/ModularToolManger/ModularToolManger/ModularToolManger.csproj @@ -56,9 +56,8 @@ False DLL\Logging.dll - - False - DLL\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll False @@ -167,6 +166,7 @@ Always + SettingsSingleFileGenerator Settings.Designer.cs @@ -183,7 +183,6 @@ - diff --git a/ModularToolManger/ModularToolManger/app.config b/ModularToolManger/ModularToolManger/app.config index 35f7aec..ee32a41 100644 --- a/ModularToolManger/ModularToolManger/app.config +++ b/ModularToolManger/ModularToolManger/app.config @@ -5,7 +5,7 @@ - + diff --git a/ModularToolManger/ModularToolManger/packages.config b/ModularToolManger/ModularToolManger/packages.config new file mode 100644 index 0000000..c8b3ae6 --- /dev/null +++ b/ModularToolManger/ModularToolManger/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file