diff --git a/WinLess/Forms/mainForm.cs b/WinLess/Forms/mainForm.cs index c1437ef..a73290b 100644 --- a/WinLess/Forms/mainForm.cs +++ b/WinLess/Forms/mainForm.cs @@ -13,7 +13,7 @@ namespace WinLess { - public partial class mainForm : Form + public partial class mainForm : Form, CompilerDispatcher { private static mainForm activeOrInActiveMainForm = null; public static mainForm ActiveOrInActiveMainForm @@ -39,7 +39,7 @@ public mainForm() activeOrInActiveMainForm = this; Program.Settings = Settings.LoadSettings(); - Program.Settings.DirectoryList.Initialize(); + Program.Settings.DirectoryList.Initialize(this); InitializeComponent(); initFilesDataGridViewCheckAllCheckBox(); @@ -87,7 +87,7 @@ public void LoadDirectories(CommandArguments args) { if(System.IO.Directory.Exists(directoryPath)) { - Models.Directory directory = Program.Settings.DirectoryList.AddDirectory(directoryPath); + Models.Directory directory = Program.Settings.DirectoryList.AddDirectory(directoryPath, this); foreach (Models.File file in directory.Files) { @@ -158,7 +158,7 @@ private void foldersListBox_DragDrop(object sender, DragEventArgs e) DirectoryInfo directoryInfo = new DirectoryInfo(fullPath); if (directoryInfo.Exists && !foldersListBox.Items.Contains(directoryInfo.FullName)) { - Program.Settings.DirectoryList.AddDirectory(directoryInfo.FullName); + Program.Settings.DirectoryList.AddDirectory(directoryInfo.FullName, this); foldersListBox_DataChanged(); SelectDirectory(); Program.Settings.SaveSettings(); @@ -344,7 +344,7 @@ private void addDirectoryButton_Click(object sender, EventArgs e) { if (folderBrowserDialog.ShowDialog() == true) { - Program.Settings.DirectoryList.AddDirectory(folderBrowserDialog.SelectedPath); + Program.Settings.DirectoryList.AddDirectory(folderBrowserDialog.SelectedPath, this); foldersListBox_DataChanged(); Program.Settings.SaveSettings(); } @@ -513,7 +513,7 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e) /// /// Compiles a list of selected LESS files /// - private void CompileSelectedFiles() + public void CompileSelectedFiles() { // Retrieve list of files from data grid List files = (List)filesDataGridView.DataSource; diff --git a/WinLess/Forms/settingsForm.Designer.cs b/WinLess/Forms/settingsForm.Designer.cs index 54704e9..06e273d 100644 --- a/WinLess/Forms/settingsForm.Designer.cs +++ b/WinLess/Forms/settingsForm.Designer.cs @@ -32,22 +32,24 @@ private void InitializeComponent() this.cancelButton = new System.Windows.Forms.Button(); this.okButton = new System.Windows.Forms.Button(); this.generalGroupBox = new System.Windows.Forms.GroupBox(); + this.checkForLessUpdatesCheckbox = new System.Windows.Forms.CheckBox(); this.startMinimizedCheckBox = new System.Windows.Forms.CheckBox(); this.startWithWindowsCheckBox = new System.Windows.Forms.CheckBox(); this.compilingGroupBox = new System.Windows.Forms.GroupBox(); + this.compileOnDirectoryChangeCheckBox = new System.Windows.Forms.CheckBox(); this.showSuccessMessagesCheckbox = new System.Windows.Forms.CheckBox(); this.compileOnSaveCheckBox = new System.Windows.Forms.CheckBox(); this.defaultMinifyCheckBox = new System.Windows.Forms.CheckBox(); - this.checkForLessUpdatesCheckbox = new System.Windows.Forms.CheckBox(); this.generalGroupBox.SuspendLayout(); this.compilingGroupBox.SuspendLayout(); this.SuspendLayout(); // // cancelButton // - this.cancelButton.Location = new System.Drawing.Point(197, 233); + this.cancelButton.Location = new System.Drawing.Point(262, 313); + this.cancelButton.Margin = new System.Windows.Forms.Padding(4); this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.Size = new System.Drawing.Size(100, 28); this.cancelButton.TabIndex = 0; this.cancelButton.Text = "Cancel"; this.cancelButton.UseVisualStyleBackColor = true; @@ -55,9 +57,10 @@ private void InitializeComponent() // // okButton // - this.okButton.Location = new System.Drawing.Point(116, 233); + this.okButton.Location = new System.Drawing.Point(154, 313); + this.okButton.Margin = new System.Windows.Forms.Padding(4); this.okButton.Name = "okButton"; - this.okButton.Size = new System.Drawing.Size(75, 23); + this.okButton.Size = new System.Drawing.Size(100, 28); this.okButton.TabIndex = 1; this.okButton.Text = "Ok"; this.okButton.UseVisualStyleBackColor = true; @@ -68,19 +71,33 @@ private void InitializeComponent() this.generalGroupBox.Controls.Add(this.checkForLessUpdatesCheckbox); this.generalGroupBox.Controls.Add(this.startMinimizedCheckBox); this.generalGroupBox.Controls.Add(this.startWithWindowsCheckBox); - this.generalGroupBox.Location = new System.Drawing.Point(13, 13); + this.generalGroupBox.Location = new System.Drawing.Point(17, 16); + this.generalGroupBox.Margin = new System.Windows.Forms.Padding(4); this.generalGroupBox.Name = "generalGroupBox"; - this.generalGroupBox.Size = new System.Drawing.Size(259, 91); + this.generalGroupBox.Padding = new System.Windows.Forms.Padding(4); + this.generalGroupBox.Size = new System.Drawing.Size(345, 112); this.generalGroupBox.TabIndex = 2; this.generalGroupBox.TabStop = false; this.generalGroupBox.Text = "General"; // + // checkForLessUpdatesCheckbox + // + this.checkForLessUpdatesCheckbox.AutoSize = true; + this.checkForLessUpdatesCheckbox.Location = new System.Drawing.Point(9, 82); + this.checkForLessUpdatesCheckbox.Margin = new System.Windows.Forms.Padding(4); + this.checkForLessUpdatesCheckbox.Name = "checkForLessUpdatesCheckbox"; + this.checkForLessUpdatesCheckbox.Size = new System.Drawing.Size(273, 21); + this.checkForLessUpdatesCheckbox.TabIndex = 2; + this.checkForLessUpdatesCheckbox.Text = "Automatically check for less.js updates"; + this.checkForLessUpdatesCheckbox.UseVisualStyleBackColor = true; + // // startMinimizedCheckBox // this.startMinimizedCheckBox.AutoSize = true; - this.startMinimizedCheckBox.Location = new System.Drawing.Point(7, 44); + this.startMinimizedCheckBox.Location = new System.Drawing.Point(9, 54); + this.startMinimizedCheckBox.Margin = new System.Windows.Forms.Padding(4); this.startMinimizedCheckBox.Name = "startMinimizedCheckBox"; - this.startMinimizedCheckBox.Size = new System.Drawing.Size(96, 17); + this.startMinimizedCheckBox.Size = new System.Drawing.Size(126, 21); this.startMinimizedCheckBox.TabIndex = 1; this.startMinimizedCheckBox.Text = "Start minimized"; this.startMinimizedCheckBox.UseVisualStyleBackColor = true; @@ -88,31 +105,46 @@ private void InitializeComponent() // startWithWindowsCheckBox // this.startWithWindowsCheckBox.AutoSize = true; - this.startWithWindowsCheckBox.Location = new System.Drawing.Point(7, 20); + this.startWithWindowsCheckBox.Location = new System.Drawing.Point(9, 25); + this.startWithWindowsCheckBox.Margin = new System.Windows.Forms.Padding(4); this.startWithWindowsCheckBox.Name = "startWithWindowsCheckBox"; - this.startWithWindowsCheckBox.Size = new System.Drawing.Size(117, 17); + this.startWithWindowsCheckBox.Size = new System.Drawing.Size(148, 21); this.startWithWindowsCheckBox.TabIndex = 0; this.startWithWindowsCheckBox.Text = "Start with Windows"; this.startWithWindowsCheckBox.UseVisualStyleBackColor = true; // // compilingGroupBox // + this.compilingGroupBox.Controls.Add(this.compileOnDirectoryChangeCheckBox); this.compilingGroupBox.Controls.Add(this.showSuccessMessagesCheckbox); this.compilingGroupBox.Controls.Add(this.compileOnSaveCheckBox); this.compilingGroupBox.Controls.Add(this.defaultMinifyCheckBox); - this.compilingGroupBox.Location = new System.Drawing.Point(13, 127); + this.compilingGroupBox.Location = new System.Drawing.Point(17, 156); + this.compilingGroupBox.Margin = new System.Windows.Forms.Padding(4); this.compilingGroupBox.Name = "compilingGroupBox"; - this.compilingGroupBox.Size = new System.Drawing.Size(259, 100); + this.compilingGroupBox.Padding = new System.Windows.Forms.Padding(4); + this.compilingGroupBox.Size = new System.Drawing.Size(345, 149); this.compilingGroupBox.TabIndex = 3; this.compilingGroupBox.TabStop = false; this.compilingGroupBox.Text = "Compiling"; // + // compileOnDirectoryChangeCheckBox + // + this.compileOnDirectoryChangeCheckBox.AutoSize = true; + this.compileOnDirectoryChangeCheckBox.Location = new System.Drawing.Point(45, 82); + this.compileOnDirectoryChangeCheckBox.Name = "compileOnDirectoryChangeCheckBox"; + this.compileOnDirectoryChangeCheckBox.Size = new System.Drawing.Size(237, 21); + this.compileOnDirectoryChangeCheckBox.TabIndex = 3; + this.compileOnDirectoryChangeCheckBox.Text = "Compile on any directory change"; + this.compileOnDirectoryChangeCheckBox.UseVisualStyleBackColor = true; + // // showSuccessMessagesCheckbox // this.showSuccessMessagesCheckbox.AutoSize = true; - this.showSuccessMessagesCheckbox.Location = new System.Drawing.Point(7, 68); + this.showSuccessMessagesCheckbox.Location = new System.Drawing.Point(9, 112); + this.showSuccessMessagesCheckbox.Margin = new System.Windows.Forms.Padding(4); this.showSuccessMessagesCheckbox.Name = "showSuccessMessagesCheckbox"; - this.showSuccessMessagesCheckbox.Size = new System.Drawing.Size(200, 17); + this.showSuccessMessagesCheckbox.Size = new System.Drawing.Size(260, 21); this.showSuccessMessagesCheckbox.TabIndex = 2; this.showSuccessMessagesCheckbox.Text = "Show message on succesful compile"; this.showSuccessMessagesCheckbox.UseVisualStyleBackColor = true; @@ -120,43 +152,37 @@ private void InitializeComponent() // compileOnSaveCheckBox // this.compileOnSaveCheckBox.AutoSize = true; - this.compileOnSaveCheckBox.Location = new System.Drawing.Point(7, 44); + this.compileOnSaveCheckBox.Location = new System.Drawing.Point(9, 54); + this.compileOnSaveCheckBox.Margin = new System.Windows.Forms.Padding(4); this.compileOnSaveCheckBox.Name = "compileOnSaveCheckBox"; - this.compileOnSaveCheckBox.Size = new System.Drawing.Size(209, 17); + this.compileOnSaveCheckBox.Size = new System.Drawing.Size(273, 21); this.compileOnSaveCheckBox.TabIndex = 1; this.compileOnSaveCheckBox.Text = "Automatically compile files when saved"; this.compileOnSaveCheckBox.UseVisualStyleBackColor = true; + this.compileOnSaveCheckBox.CheckedChanged += new System.EventHandler(this.compileOnSaveCheckBox_CheckedChanged); // // defaultMinifyCheckBox // this.defaultMinifyCheckBox.AutoSize = true; - this.defaultMinifyCheckBox.Location = new System.Drawing.Point(7, 21); + this.defaultMinifyCheckBox.Location = new System.Drawing.Point(9, 26); + this.defaultMinifyCheckBox.Margin = new System.Windows.Forms.Padding(4); this.defaultMinifyCheckBox.Name = "defaultMinifyCheckBox"; - this.defaultMinifyCheckBox.Size = new System.Drawing.Size(102, 17); + this.defaultMinifyCheckBox.Size = new System.Drawing.Size(132, 21); this.defaultMinifyCheckBox.TabIndex = 0; this.defaultMinifyCheckBox.Text = "Minify by default"; this.defaultMinifyCheckBox.UseVisualStyleBackColor = true; // - // checkForLessUpdatesCheckbox - // - this.checkForLessUpdatesCheckbox.AutoSize = true; - this.checkForLessUpdatesCheckbox.Location = new System.Drawing.Point(7, 67); - this.checkForLessUpdatesCheckbox.Name = "checkForLessUpdatesCheckbox"; - this.checkForLessUpdatesCheckbox.Size = new System.Drawing.Size(208, 17); - this.checkForLessUpdatesCheckbox.TabIndex = 2; - this.checkForLessUpdatesCheckbox.Text = "Automatically check for less.js updates"; - this.checkForLessUpdatesCheckbox.UseVisualStyleBackColor = true; - // // settingsForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(289, 268); + this.ClientSize = new System.Drawing.Size(385, 354); this.Controls.Add(this.compilingGroupBox); this.Controls.Add(this.generalGroupBox); this.Controls.Add(this.okButton); this.Controls.Add(this.cancelButton); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Margin = new System.Windows.Forms.Padding(4); this.Name = "settingsForm"; this.Text = "Settings"; this.generalGroupBox.ResumeLayout(false); @@ -179,5 +205,6 @@ private void InitializeComponent() private System.Windows.Forms.CheckBox compileOnSaveCheckBox; private System.Windows.Forms.CheckBox showSuccessMessagesCheckbox; private System.Windows.Forms.CheckBox checkForLessUpdatesCheckbox; + private System.Windows.Forms.CheckBox compileOnDirectoryChangeCheckBox; } } \ No newline at end of file diff --git a/WinLess/Forms/settingsForm.cs b/WinLess/Forms/settingsForm.cs index 64001af..68574f0 100644 --- a/WinLess/Forms/settingsForm.cs +++ b/WinLess/Forms/settingsForm.cs @@ -22,8 +22,10 @@ private void loadSettings() startMinimizedCheckBox.Checked = Program.Settings.StartMinified; checkForLessUpdatesCheckbox.Checked = Program.Settings.CheckForLessUpdates; defaultMinifyCheckBox.Checked = Program.Settings.DefaultMinify; + compileOnDirectoryChangeCheckBox.Checked = Program.Settings.CompileOnDirectoryChange; compileOnSaveCheckBox.Checked = Program.Settings.CompileOnSave; showSuccessMessagesCheckbox.Checked = Program.Settings.ShowSuccessMessages; + compileOnDirectoryChangeCheckBox.Enabled = compileOnSaveCheckBox.Checked; } private void saveSettings() @@ -33,6 +35,7 @@ private void saveSettings() Program.Settings.CheckForLessUpdates = checkForLessUpdatesCheckbox.Checked; Program.Settings.DefaultMinify = defaultMinifyCheckBox.Checked; Program.Settings.CompileOnSave = compileOnSaveCheckBox.Checked; + Program.Settings.CompileOnDirectoryChange = compileOnDirectoryChangeCheckBox.Checked; Program.Settings.ShowSuccessMessages = showSuccessMessagesCheckbox.Checked; Program.Settings.SaveSettings(); } @@ -47,5 +50,10 @@ private void okButton_Click(object sender, EventArgs e) saveSettings(); this.Close(); } + + private void compileOnSaveCheckBox_CheckedChanged(object sender, EventArgs e) + { + compileOnDirectoryChangeCheckBox.Enabled = compileOnSaveCheckBox.Checked; + } } } diff --git a/WinLess/Models/CompilerDispatcher.cs b/WinLess/Models/CompilerDispatcher.cs new file mode 100644 index 0000000..4835b18 --- /dev/null +++ b/WinLess/Models/CompilerDispatcher.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WinLess.Models +{ + public interface CompilerDispatcher + { + void CompileSelectedFiles(); + } +} diff --git a/WinLess/Models/DirectoryList.cs b/WinLess/Models/DirectoryList.cs index b309d1c..5545d6e 100644 --- a/WinLess/Models/DirectoryList.cs +++ b/WinLess/Models/DirectoryList.cs @@ -19,21 +19,21 @@ public DirectoryList() Directories = new List(); } - public void Initialize() + public void Initialize( CompilerDispatcher dispacher) { RemoveDeletedDirectories(); CheckAllFilesForImports(); - StartWatchers(); + StartWatchers(dispacher); } - public Directory AddDirectory(string path) + public Directory AddDirectory(string path, CompilerDispatcher dispacher) { Directory directory = GetDirectory(path); if (directory == null) { directory = new Models.Directory(path); Directories.Add(directory); - AddWatcher(directory); + AddWatcher(directory, dispacher); Program.Settings.SaveSettings(); CheckAllFilesForImports(); } @@ -122,15 +122,15 @@ private void CheckAllFilesForImports() } } - public void StartWatchers() + public void StartWatchers( CompilerDispatcher dispacher) { foreach (Models.Directory directory in Directories) { - this.AddWatcher(directory); + this.AddWatcher(directory, dispacher); } } - private void AddWatcher(Models.Directory directory) + private void AddWatcher(Models.Directory directory, CompilerDispatcher dispacher) { try { @@ -140,13 +140,34 @@ private void AddWatcher(Models.Directory directory) { fileSystemWatchers = new List(); } + + Action compileOnChage = delegate(object sender, System.IO.FileSystemEventArgs e) + { + if (Program.Settings.CompileOnSave && IsNewFileChange(e) && IsLessFile(e.FullPath)) + { + Models.File file = Program.Settings.DirectoryList.GetFile(e.FullPath); + if (file != null) + { + if (Program.Settings.CompileOnDirectoryChange) + { + dispacher.CompileSelectedFiles(); + } + else + { + file.Compile(); + previousFileChangedPath = file.FullPath; + previousFileChangedTime = DateTime.Now; + } + } + } + }; FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(); fileSystemWatcher.Path = directory.FullPath; fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.Filter = "*.*"; fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.LastAccess | NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.CreationTime | NotifyFilters.Attributes; - fileSystemWatcher.Changed += FileSystemWatcher_Changed; + fileSystemWatcher.Changed += new FileSystemEventHandler(compileOnChage); fileSystemWatcher.EnableRaisingEvents = true; fileSystemWatchers.Add(fileSystemWatcher); @@ -181,20 +202,7 @@ private void RemoveWatcher(string path) } } - private void FileSystemWatcher_Changed(object sender, System.IO.FileSystemEventArgs e) - { - - if (Program.Settings.CompileOnSave && IsNewFileChange(e) && IsLessFile(e.FullPath)) - { - Models.File file = Program.Settings.DirectoryList.GetFile(e.FullPath); - if (file != null) - { - file.Compile(); - previousFileChangedPath = file.FullPath; - previousFileChangedTime = DateTime.Now; - } - } - } + private bool IsNewFileChange(System.IO.FileSystemEventArgs e) { diff --git a/WinLess/Settings.cs b/WinLess/Settings.cs index 16b7f54..2e8418b 100644 --- a/WinLess/Settings.cs +++ b/WinLess/Settings.cs @@ -16,6 +16,7 @@ public Settings() DirectoryList = new DirectoryList(); DefaultMinify = true; CompileOnSave = true; + CompileOnDirectoryChange = false; ShowSuccessMessages = false; StartWithWindows = true; StartMinified = false; @@ -25,6 +26,7 @@ public Settings() public DirectoryList DirectoryList { get; set; } public bool DefaultMinify { get; set; } public bool CompileOnSave { get; set; } + public bool CompileOnDirectoryChange { get; set; } public bool ShowSuccessMessages { get; set; } public bool StartMinified { get; set; } public bool CheckForLessUpdates { get; set; } diff --git a/WinLess/WinLess.csproj b/WinLess/WinLess.csproj index b3f7cc7..951fa2d 100644 --- a/WinLess/WinLess.csproj +++ b/WinLess/WinLess.csproj @@ -80,6 +80,7 @@ + @@ -107,7 +108,7 @@ - ROBOCOPY "$(ProjectDir)node_modules" "$(TargetDir)node_modules" * /COPYALL /S + ROBOCOPY "$(ProjectDir)node_modules" "$(TargetDir)node_modules" * /COPY:DATSO /S EXIT 0