diff --git a/SparkleShare/Windows/SparkleEventLogWindow.xaml b/SparkleShare/Windows/SparkleEventLogWindow.xaml index 57ba9c7e..a43d38f3 100644 --- a/SparkleShare/Windows/SparkleEventLogWindow.xaml +++ b/SparkleShare/Windows/SparkleEventLogWindow.xaml @@ -28,9 +28,9 @@ - + See: http://stackoverflow.com/questions/7300975/prevent-parent-from-being-resized-by-child --> diff --git a/SparkleShare/Windows/SparkleEventLogWindow.xaml.cs b/SparkleShare/Windows/SparkleEventLogWindow.xaml.cs index f690aedc..c9861214 100644 --- a/SparkleShare/Windows/SparkleEventLogWindow.xaml.cs +++ b/SparkleShare/Windows/SparkleEventLogWindow.xaml.cs @@ -1,20 +1,37 @@ -using System.Windows; +// SparkleShare, a collaboration and sharing tool. +// Copyright (C) 2010 Hylke Bons +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Security.Permissions; +using System.Text; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +using Microsoft.Win32; namespace SparkleShare { - using System; - using System.ComponentModel; - using System.IO; - using System.Runtime.InteropServices; - using System.Windows.Controls; - using System.Windows.Media; - using System.Windows.Media.Imaging; - - using Microsoft.Win32; - - /// - /// Logics for the recent-changes-window. - /// public partial class SparkleEventLogWindow : Window { public SparkleEventLogController Controller = new SparkleEventLogController (); @@ -22,152 +39,137 @@ namespace SparkleShare [DllImport("urlmon.dll")] [PreserveSig] [return: MarshalAs(UnmanagedType.Error)] - static extern int CoInternetSetFeatureEnabled(int feature, [MarshalAs(UnmanagedType.U4)] int flags, bool enable); + static extern int CoInternetSetFeatureEnabled (int feature, [MarshalAs(UnmanagedType.U4)] int flags, bool enable); + - /// - /// Initializes a new instance of the class. - /// public SparkleEventLogWindow () { - this.InitializeComponent (); + InitializeComponent (); - // Hide the minimize and maximize buttons. - this.SourceInitialized += (sender, args) => this.HideMinimizeAndMaximizeButtons(); - // Set some window-properties from code. - this.Background = new SolidColorBrush (Color.FromRgb(240, 240, 240)); - this.AllowsTransparency = false; - this.Icon = SparkleUIHelpers.GetImageSource ("sparkleshare-app", "ico"); - this.WindowStartupLocation = WindowStartupLocation.CenterScreen; + Background = new SolidColorBrush (Color.FromRgb(240, 240, 240)); + AllowsTransparency = false; + Icon = SparkleUIHelpers.GetImageSource ("sparkleshare-app", "ico"); + WindowStartupLocation = WindowStartupLocation.CenterScreen; - // Write images to temp-folder. - this.WriteOutImages (); + WriteOutImages (); - // Set values from controller to ui. this.label_Size.Content = "Size: " + Controller.Size; this.label_History.Content = "History: " + Controller.HistorySize; this.webbrowser.ObjectForScripting = new SparkleScriptingObject (); - // Disable annoying IE clicking sound + + // Disable annoying IE clicking sound CoInternetSetFeatureEnabled (21, 0x00000002, true); - // Tell controller on closing event. - this.Closing += this.OnClosing; + Closing += this.OnClosing; - // Show the window on controllers request. - this.Controller.ShowWindowEvent += () => this.Dispatcher.BeginInvoke ( - (Action)(() => { - this.Show (); - this.Activate (); - this.BringIntoView (); + Controller.ShowWindowEvent += delegate { + Dispatcher.BeginInvoke ((Action) (() => { + Show (); + Activate (); + BringIntoView (); + })); + }; + + Controller.HideWindowEvent += delegate { + Dispatcher.BeginInvoke ((Action) (() => { + Hide (); + this.spinner.Visibility = Visibility.Visible; + this.webbrowser.Visibility = Visibility.Collapsed; + })); + }; + + Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) { + Dispatcher.BeginInvoke ((Action) (() => { + this.label_Size.Content = "Size: " + size; + this.label_History.Content = "History: " + history_size; })); + }; - // Hide the window on controllers request. - // Also hide the webbrowser-element and show the spinner. - this.Controller.HideWindowEvent += () => this.Dispatcher.BeginInvoke ( - (Action)(() => { - this.Hide (); - this.spinner.Visibility = Visibility.Visible; - this.webbrowser.Visibility = Visibility.Collapsed; - })); + Controller.UpdateChooserEvent += delegate (string [] folders) { + Dispatcher.BeginInvoke ((Action) (() => + UpdateChooser (folders)) + ); + }; - // Update labels on controllers request. - this.Controller.UpdateSizeInfoEvent += (size, history_size) => this.Dispatcher.BeginInvoke ( - (Action)(() => { - this.label_Size.Content = "Size: " + size; - this.label_History.Content = "History: " + history_size; - })); + Controller.UpdateChooserEnablementEvent += delegate (bool enabled) { + Dispatcher.BeginInvoke ((Action) (() => + this.combobox.IsEnabled = enabled + )); + }; - // Update the combobox-elements. - this.Controller.UpdateChooserEvent += folders => this.Dispatcher.BeginInvoke ( - (Action)(() => this.UpdateChooser (folders))); + Controller.UpdateContentEvent += delegate (string html) { + Dispatcher.BeginInvoke ((Action) (() => { + UpdateContent (html); - // Update the enabled-state of the combobox. - this.Controller.UpdateChooserEnablementEvent += enabled => this.Dispatcher.BeginInvoke ( - (Action)(() => this.combobox.IsEnabled = enabled)); + this.spinner.Visibility = Visibility.Collapsed; + this.webbrowser.Visibility = Visibility.Visible; + })); + }; - // Update the content of the webbrowser. - this.Controller.UpdateContentEvent += html => this.Dispatcher.BeginInvoke ((Action)(() => { - this.UpdateContent (html); - - this.spinner.Visibility = Visibility.Collapsed; - this.webbrowser.Visibility = Visibility.Visible; - })); - - // Show the spinner if the content is loading. - this.Controller.ContentLoadingEvent += () => this.Dispatcher.BeginInvoke ( + Controller.ContentLoadingEvent += () => this.Dispatcher.BeginInvoke ( (Action)(() => { this.spinner.Visibility = Visibility.Visible; this.spinner.Start (); this.webbrowser.Visibility = Visibility.Collapsed; })); - // Show the save-file-dialog on controllers request. - this.Controller.ShowSaveDialogEvent += - (file_name, target_folder_path) => this.Dispatcher.BeginInvoke ( - (Action)(() => { - SaveFileDialog dialog = new SaveFileDialog () - { - FileName = file_name, - InitialDirectory = target_folder_path, - Title = "Restore from History", - DefaultExt = "." + Path.GetExtension (file_name), - Filter = "All Files|*.*" - }; + Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) { + Dispatcher.BeginInvoke ((Action) (() => { + SaveFileDialog dialog = new SaveFileDialog () { + FileName = file_name, + InitialDirectory = target_folder_path, + Title = "Restore from History", + DefaultExt = "." + Path.GetExtension (file_name), + Filter = "All Files|*.*" + }; - bool? result = dialog.ShowDialog (this); + bool? result = dialog.ShowDialog (this); + + if (result == true) + Controller.SaveDialogCompleted (dialog.FileName); + else + Controller.SaveDialogCancelled (); + })); + }; + } - if (result == true) this.Controller.SaveDialogCompleted (dialog.FileName); - else this.Controller.SaveDialogCancelled (); - })); - } - /// - /// Called when [closing]. - /// Suppress the closing and asks controller to hide this window. - /// - /// The sender. - /// The instance containing the event data. private void OnClosing (object sender, CancelEventArgs cancel_event_args) { - this.Controller.WindowClosed (); + Controller.WindowClosed (); cancel_event_args.Cancel = true; } - /// - /// Updates the content of the webbrowser. - /// - /// The HTML. + private void UpdateContent (string html) { string pixmaps_path = Path.Combine (SparkleLib.SparkleConfig.DefaultConfig.TmpPath, "Pixmaps"); pixmaps_path = pixmaps_path.Replace ("\\", "/"); - html = html.Replace("", "'Segoe UI', sans-serif"); - html = html.Replace("", "13px"); - html = html.Replace("", "12px"); - html = html.Replace("", "#bbb"); - html = html.Replace("", "#ddd"); - html = html.Replace("", "90%"); - html = html.Replace("", "#f5f5f5"); - html = html.Replace("", "#0085cf"); - html = html.Replace("", "#009ff8"); - html = html.Replace("", pixmaps_path); - html = html.Replace("", pixmaps_path + "/document-added-12.png"); - html = html.Replace("", pixmaps_path + "/document-edited-12.png"); - html = html.Replace("", pixmaps_path + "/document-deleted-12.png"); - html = html.Replace("", pixmaps_path + "/document-moved-12.png"); + html = html.Replace ("", "'Segoe UI', sans-serif"); + html = html.Replace ("", "13px"); + html = html.Replace ("", "12px"); + html = html.Replace ("", "#bbb"); + html = html.Replace ("", "#ddd"); + html = html.Replace ("", "90%"); + html = html.Replace ("", "#f5f5f5"); + html = html.Replace ("", "#0085cf"); + html = html.Replace ("", "#009ff8"); + html = html.Replace ("", pixmaps_path); + html = html.Replace ("", pixmaps_path + "/document-added-12.png"); + html = html.Replace ("", pixmaps_path + "/document-edited-12.png"); + html = html.Replace ("", pixmaps_path + "/document-deleted-12.png"); + html = html.Replace ("", pixmaps_path + "/document-moved-12.png"); - this.spinner.Stop(); + this.spinner.Stop (); this.webbrowser.ObjectForScripting = new SparkleScriptingObject (); this.webbrowser.NavigateToString (html); } - /// - /// Updates the combobox-items. - /// - /// The folders. + public void UpdateChooser (string [] folders) { if (folders == null) { @@ -176,73 +178,84 @@ namespace SparkleShare this.combobox.Items.Clear (); this.combobox.Items.Add (new ComboBoxItem () { Content = "Summary" }); - this.combobox.Items.Add(new Separator()); - this.combobox.SelectedItem = combobox.Items[0]; + this.combobox.Items.Add (new Separator ()); + this.combobox.SelectedItem = combobox.Items [0]; int row = 2; - foreach (string folder in folders) - { - this.combobox.Items.Add(new ComboBoxItem() { Content = folder } ); + foreach (string folder in folders) { + this.combobox.Items.Add (new ComboBoxItem () { Content = folder } ); - if (folder.Equals (Controller.SelectedFolder)) { + if (folder.Equals (Controller.SelectedFolder)) this.combobox.SelectedItem = this.combobox.Items [row]; - } row++; } this.combobox.SelectionChanged += delegate { - Dispatcher.BeginInvoke((Action)delegate { + Dispatcher.BeginInvoke ((Action) delegate { int index = this.combobox.SelectedIndex; - if (index == 0) { + if (index == 0) Controller.SelectedFolder = null; - } else { - Controller.SelectedFolder = (string)((ComboBoxItem)this.combobox.Items[index]).Content; - } + else + Controller.SelectedFolder = (string) ((ComboBoxItem) this.combobox.Items [index]).Content; }); }; } - /// - /// Writes the images from the pixel-map to the temp-folder. - /// + private void WriteOutImages () { string tmp_path = SparkleLib.SparkleConfig.DefaultConfig.TmpPath; - string pixmaps_path = Path.Combine(tmp_path, "Pixmaps"); + string pixmaps_path = Path.Combine (tmp_path, "Pixmaps"); - if (!Directory.Exists(pixmaps_path)) + if (!Directory.Exists (pixmaps_path)) { - Directory.CreateDirectory(pixmaps_path); + Directory.CreateDirectory (pixmaps_path); - File.SetAttributes(tmp_path, File.GetAttributes(tmp_path) | FileAttributes.Hidden); + File.SetAttributes (tmp_path, File.GetAttributes (tmp_path) | FileAttributes.Hidden); } - BitmapSource image = SparkleUIHelpers.GetImageSource("user-icon-default"); - string file_path = Path.Combine(pixmaps_path, "user-icon-default.png"); + BitmapSource image = SparkleUIHelpers.GetImageSource ("user-icon-default"); + string file_path = Path.Combine (pixmaps_path, "user-icon-default.png"); - using (FileStream stream = new FileStream(file_path, FileMode.Create)) + using (FileStream stream = new FileStream (file_path, FileMode.Create)) { - BitmapEncoder encoder = new PngBitmapEncoder(); - encoder.Frames.Add(BitmapFrame.Create(image)); - encoder.Save(stream); + BitmapEncoder encoder = new PngBitmapEncoder (); + encoder.Frames.Add (BitmapFrame.Create (image)); + encoder.Save (stream); } - string[] actions = new string[] { "added", "deleted", "edited", "moved" }; + string[] actions = new string [] { "added", "deleted", "edited", "moved" }; foreach (string action in actions) { - image = SparkleUIHelpers.GetImageSource("document-" + action + "-12"); - file_path = Path.Combine(pixmaps_path, "document-" + action + "-12.png"); + image = SparkleUIHelpers.GetImageSource ("document-" + action + "-12"); + file_path = Path.Combine (pixmaps_path, "document-" + action + "-12.png"); - using (FileStream stream = new FileStream(file_path, FileMode.Create)) + using (FileStream stream = new FileStream (file_path, FileMode.Create)) { - BitmapEncoder encoder = new PngBitmapEncoder(); - encoder.Frames.Add(BitmapFrame.Create(image)); - encoder.Save(stream); + BitmapEncoder encoder = new PngBitmapEncoder (); + encoder.Frames.Add (BitmapFrame.Create(image)); + encoder.Save (stream); } } } } + + + + + + [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] + [ComVisible(true)] + public class SparkleScriptingObject + { + public void LinkClicked(string url) + { + Program.UI.EventLog.Controller.LinkClicked(url); + } + } + + } diff --git a/SparkleShare/Windows/SparkleScriptingObject.cs b/SparkleShare/Windows/SparkleScriptingObject.cs deleted file mode 100644 index 171ee087..00000000 --- a/SparkleShare/Windows/SparkleScriptingObject.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using System.Runtime.InteropServices; -using System.Security.Permissions; - -namespace SparkleShare -{ - [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] - [ComVisible(true)] - public class SparkleScriptingObject - { - public void LinkClicked(string url) - { - Program.UI.EventLog.Controller.LinkClicked(url); - } - } -} diff --git a/SparkleShare/Windows/SparkleShare.csproj b/SparkleShare/Windows/SparkleShare.csproj index 5b437b41..2b656a21 100644 --- a/SparkleShare/Windows/SparkleShare.csproj +++ b/SparkleShare/Windows/SparkleShare.csproj @@ -30,7 +30,8 @@ false true Pixmaps\sparkleshare-app.ico - + + none @@ -79,7 +80,6 @@ SparkleEventLogWindow.xaml - @@ -102,7 +102,6 @@ - diff --git a/SparkleShare/Windows/WPFChromeExtensions.cs b/SparkleShare/Windows/WPFChromeExtensions.cs deleted file mode 100644 index 175e7a7c..00000000 --- a/SparkleShare/Windows/WPFChromeExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using System.Runtime.InteropServices; -using System.Windows; - -namespace SparkleShare -{ - /// - /// Thanks to Matt Hamilton for this code! - /// See http://stackoverflow.com/questions/339620/how-do-i-remove-minimize-and-maximize-from-a-resizable-window-in-wpf - /// - internal static class WindowExtensions { - // from winuser.h - private const int GWL_STYLE = -16, - WS_MAXIMIZEBOX = 0x10000, - WS_MINIMIZEBOX = 0x20000; - - [DllImport("user32.dll")] - extern private static int GetWindowLong (IntPtr hwnd, int index); - - [DllImport("user32.dll")] - extern private static int SetWindowLong (IntPtr hwnd, int index, int value); - - internal static void HideMinimizeAndMaximizeButtons (this Window window) - { - IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle; - var currentStyle = GetWindowLong (hwnd, GWL_STYLE); - - SetWindowLong (hwnd, GWL_STYLE, (currentStyle & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX)); - } - } -}