windows eventlog: Fix coding style and merge #1439

This commit is contained in:
Hylke Bons 2014-05-08 22:23:09 -07:00
parent 7dbd7c9a86
commit 8aee80d876
5 changed files with 165 additions and 208 deletions

View file

@ -28,9 +28,9 @@
<sparkleShare:SparkleSpinner x:Name="spinner" /> <sparkleShare:SparkleSpinner x:Name="spinner" />
<WebBrowser x:Name="webbrowser" Height="{Binding ElementName=sizingControlHeight, Path=ActualHeight}" Width="{Binding ElementName=sizingControlWidth, Path=ActualWidth}" /> <WebBrowser x:Name="webbrowser" Height="{Binding ElementName=sizingControlHeight, Path=ActualHeight}" Width="{Binding ElementName=sizingControlWidth, Path=ActualWidth}" />
<!-- Unfortunatly WPF allways resizes from child to parent. Unfortunatley the webbrowser takes all space it gets -> stupid! <!-- WPF always resizes from child to parent. Unfortunately the webbrowser takes all space it gets.
To correct this "feature" we use a dummy control in a different column to bind the height to. To correct this "feature" we use a dummy control in a different column to bind the height to.
Compare: http://stackoverflow.com/questions/7300975/prevent-parent-from-being-resized-by-child --> See: http://stackoverflow.com/questions/7300975/prevent-parent-from-being-resized-by-child -->
<Rectangle Name="sizingControlHeight" Grid.Column="1" Visibility="Hidden" /> <Rectangle Name="sizingControlHeight" Grid.Column="1" Visibility="Hidden" />
<Rectangle Name="sizingControlWidth" Grid.Column="0" Grid.Row="1" Visibility="Hidden" /> <Rectangle Name="sizingControlWidth" Grid.Column="0" Grid.Row="1" Visibility="Hidden" />
</Grid> </Grid>

View file

@ -1,20 +1,37 @@
using System.Windows; // SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
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 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;
/// <summary>
/// Logics for the recent-changes-window.
/// </summary>
public partial class SparkleEventLogWindow : Window public partial class SparkleEventLogWindow : Window
{ {
public SparkleEventLogController Controller = new SparkleEventLogController (); public SparkleEventLogController Controller = new SparkleEventLogController ();
@ -22,152 +39,137 @@ namespace SparkleShare
[DllImport("urlmon.dll")] [DllImport("urlmon.dll")]
[PreserveSig] [PreserveSig]
[return: MarshalAs(UnmanagedType.Error)] [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);
/// <summary>
/// Initializes a new instance of the <see cref="SparkleEventLogWindow"/> class.
/// </summary>
public SparkleEventLogWindow () public SparkleEventLogWindow ()
{ {
this.InitializeComponent (); InitializeComponent ();
// Hide the minimize and maximize buttons. Background = new SolidColorBrush (Color.FromRgb(240, 240, 240));
this.SourceInitialized += (sender, args) => this.HideMinimizeAndMaximizeButtons(); AllowsTransparency = false;
// Set some window-properties from code. Icon = SparkleUIHelpers.GetImageSource ("sparkleshare-app", "ico");
this.Background = new SolidColorBrush (Color.FromRgb(240, 240, 240)); WindowStartupLocation = WindowStartupLocation.CenterScreen;
this.AllowsTransparency = false;
this.Icon = SparkleUIHelpers.GetImageSource ("sparkleshare-app", "ico");
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
// Write images to temp-folder. WriteOutImages ();
this.WriteOutImages ();
// Set values from controller to ui.
this.label_Size.Content = "Size: " + Controller.Size; this.label_Size.Content = "Size: " + Controller.Size;
this.label_History.Content = "History: " + Controller.HistorySize; this.label_History.Content = "History: " + Controller.HistorySize;
this.webbrowser.ObjectForScripting = new SparkleScriptingObject (); this.webbrowser.ObjectForScripting = new SparkleScriptingObject ();
// Disable annoying IE clicking sound
// Disable annoying IE clicking sound
CoInternetSetFeatureEnabled (21, 0x00000002, true); CoInternetSetFeatureEnabled (21, 0x00000002, true);
// Tell controller on closing event. Closing += this.OnClosing;
this.Closing += this.OnClosing;
// Show the window on controllers request. Controller.ShowWindowEvent += delegate {
this.Controller.ShowWindowEvent += () => this.Dispatcher.BeginInvoke ( Dispatcher.BeginInvoke ((Action) (() => {
(Action)(() => { Show ();
this.Show (); Activate ();
this.Activate (); BringIntoView ();
this.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. Controller.UpdateChooserEvent += delegate (string [] folders) {
// Also hide the webbrowser-element and show the spinner. Dispatcher.BeginInvoke ((Action) (() =>
this.Controller.HideWindowEvent += () => this.Dispatcher.BeginInvoke ( UpdateChooser (folders))
(Action)(() => { );
this.Hide (); };
this.spinner.Visibility = Visibility.Visible;
this.webbrowser.Visibility = Visibility.Collapsed;
}));
// Update labels on controllers request. Controller.UpdateChooserEnablementEvent += delegate (bool enabled) {
this.Controller.UpdateSizeInfoEvent += (size, history_size) => this.Dispatcher.BeginInvoke ( Dispatcher.BeginInvoke ((Action) (() =>
(Action)(() => { this.combobox.IsEnabled = enabled
this.label_Size.Content = "Size: " + size; ));
this.label_History.Content = "History: " + history_size; };
}));
// Update the combobox-elements. Controller.UpdateContentEvent += delegate (string html) {
this.Controller.UpdateChooserEvent += folders => this.Dispatcher.BeginInvoke ( Dispatcher.BeginInvoke ((Action) (() => {
(Action)(() => this.UpdateChooser (folders))); UpdateContent (html);
// Update the enabled-state of the combobox. this.spinner.Visibility = Visibility.Collapsed;
this.Controller.UpdateChooserEnablementEvent += enabled => this.Dispatcher.BeginInvoke ( this.webbrowser.Visibility = Visibility.Visible;
(Action)(() => this.combobox.IsEnabled = enabled)); }));
};
// Update the content of the webbrowser. Controller.ContentLoadingEvent += () => this.Dispatcher.BeginInvoke (
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 (
(Action)(() => { (Action)(() => {
this.spinner.Visibility = Visibility.Visible; this.spinner.Visibility = Visibility.Visible;
this.spinner.Start (); this.spinner.Start ();
this.webbrowser.Visibility = Visibility.Collapsed; this.webbrowser.Visibility = Visibility.Collapsed;
})); }));
// Show the save-file-dialog on controllers request. Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) {
this.Controller.ShowSaveDialogEvent += Dispatcher.BeginInvoke ((Action) (() => {
(file_name, target_folder_path) => this.Dispatcher.BeginInvoke ( SaveFileDialog dialog = new SaveFileDialog () {
(Action)(() => { FileName = file_name,
SaveFileDialog dialog = new SaveFileDialog () InitialDirectory = target_folder_path,
{ Title = "Restore from History",
FileName = file_name, DefaultExt = "." + Path.GetExtension (file_name),
InitialDirectory = target_folder_path, Filter = "All Files|*.*"
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 ();
}));
}
/// <summary>
/// Called when [closing].
/// Suppress the closing and asks controller to hide this window.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="cancel_event_args">The <see cref="CancelEventArgs"/> instance containing the event data.</param>
private void OnClosing (object sender, CancelEventArgs cancel_event_args) private void OnClosing (object sender, CancelEventArgs cancel_event_args)
{ {
this.Controller.WindowClosed (); Controller.WindowClosed ();
cancel_event_args.Cancel = true; cancel_event_args.Cancel = true;
} }
/// <summary>
/// Updates the content of the webbrowser.
/// </summary>
/// <param name="html">The HTML.</param>
private void UpdateContent (string html) private void UpdateContent (string html)
{ {
string pixmaps_path = Path.Combine (SparkleLib.SparkleConfig.DefaultConfig.TmpPath, "Pixmaps"); string pixmaps_path = Path.Combine (SparkleLib.SparkleConfig.DefaultConfig.TmpPath, "Pixmaps");
pixmaps_path = pixmaps_path.Replace ("\\", "/"); pixmaps_path = pixmaps_path.Replace ("\\", "/");
html = html.Replace("<a href=", "<a class='windows' href="); html = html.Replace ("<a href=", "<a class='windows' href=");
html = html.Replace("<!-- $body-font-family -->", "'Segoe UI', sans-serif"); html = html.Replace ("<!-- $body-font-family -->", "'Segoe UI', sans-serif");
html = html.Replace("<!-- $day-entry-header-font-size -->", "13px"); html = html.Replace ("<!-- $day-entry-header-font-size -->", "13px");
html = html.Replace("<!-- $body-font-size -->", "12px"); html = html.Replace ("<!-- $body-font-size -->", "12px");
html = html.Replace("<!-- $secondary-font-color -->", "#bbb"); html = html.Replace ("<!-- $secondary-font-color -->", "#bbb");
html = html.Replace("<!-- $small-color -->", "#ddd"); html = html.Replace ("<!-- $small-color -->", "#ddd");
html = html.Replace("<!-- $small-font-size -->", "90%"); html = html.Replace ("<!-- $small-font-size -->", "90%");
html = html.Replace("<!-- $day-entry-header-background-color -->", "#f5f5f5"); html = html.Replace ("<!-- $day-entry-header-background-color -->", "#f5f5f5");
html = html.Replace("<!-- $a-color -->", "#0085cf"); html = html.Replace ("<!-- $a-color -->", "#0085cf");
html = html.Replace("<!-- $a-hover-color -->", "#009ff8"); html = html.Replace ("<!-- $a-hover-color -->", "#009ff8");
html = html.Replace("<!-- $pixmaps-path -->", pixmaps_path); html = html.Replace ("<!-- $pixmaps-path -->", pixmaps_path);
html = html.Replace("<!-- $document-added-background-image -->", pixmaps_path + "/document-added-12.png"); html = html.Replace ("<!-- $document-added-background-image -->", pixmaps_path + "/document-added-12.png");
html = html.Replace("<!-- $document-edited-background-image -->", pixmaps_path + "/document-edited-12.png"); html = html.Replace ("<!-- $document-edited-background-image -->", pixmaps_path + "/document-edited-12.png");
html = html.Replace("<!-- $document-deleted-background-image -->", pixmaps_path + "/document-deleted-12.png"); html = html.Replace ("<!-- $document-deleted-background-image -->", pixmaps_path + "/document-deleted-12.png");
html = html.Replace("<!-- $document-moved-background-image -->", pixmaps_path + "/document-moved-12.png"); html = html.Replace ("<!-- $document-moved-background-image -->", pixmaps_path + "/document-moved-12.png");
this.spinner.Stop(); this.spinner.Stop ();
this.webbrowser.ObjectForScripting = new SparkleScriptingObject (); this.webbrowser.ObjectForScripting = new SparkleScriptingObject ();
this.webbrowser.NavigateToString (html); this.webbrowser.NavigateToString (html);
} }
/// <summary>
/// Updates the combobox-items.
/// </summary>
/// <param name="folders">The folders.</param>
public void UpdateChooser (string [] folders) public void UpdateChooser (string [] folders)
{ {
if (folders == null) { if (folders == null) {
@ -176,73 +178,84 @@ namespace SparkleShare
this.combobox.Items.Clear (); this.combobox.Items.Clear ();
this.combobox.Items.Add (new ComboBoxItem () { Content = "Summary" }); this.combobox.Items.Add (new ComboBoxItem () { Content = "Summary" });
this.combobox.Items.Add(new Separator()); this.combobox.Items.Add (new Separator ());
this.combobox.SelectedItem = combobox.Items[0]; this.combobox.SelectedItem = combobox.Items [0];
int row = 2; int row = 2;
foreach (string folder in folders) foreach (string folder in folders) {
{ this.combobox.Items.Add (new ComboBoxItem () { Content = folder } );
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]; this.combobox.SelectedItem = this.combobox.Items [row];
}
row++; row++;
} }
this.combobox.SelectionChanged += delegate { this.combobox.SelectionChanged += delegate {
Dispatcher.BeginInvoke((Action)delegate { Dispatcher.BeginInvoke ((Action) delegate {
int index = this.combobox.SelectedIndex; int index = this.combobox.SelectedIndex;
if (index == 0) { if (index == 0)
Controller.SelectedFolder = null; Controller.SelectedFolder = null;
} else { else
Controller.SelectedFolder = (string)((ComboBoxItem)this.combobox.Items[index]).Content; Controller.SelectedFolder = (string) ((ComboBoxItem) this.combobox.Items [index]).Content;
}
}); });
}; };
} }
/// <summary>
/// Writes the images from the pixel-map to the temp-folder.
/// </summary>
private void WriteOutImages () private void WriteOutImages ()
{ {
string tmp_path = SparkleLib.SparkleConfig.DefaultConfig.TmpPath; 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"); BitmapSource image = SparkleUIHelpers.GetImageSource ("user-icon-default");
string file_path = Path.Combine(pixmaps_path, "user-icon-default.png"); 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(); BitmapEncoder encoder = new PngBitmapEncoder ();
encoder.Frames.Add(BitmapFrame.Create(image)); encoder.Frames.Add (BitmapFrame.Create (image));
encoder.Save(stream); encoder.Save (stream);
} }
string[] actions = new string[] { "added", "deleted", "edited", "moved" }; string[] actions = new string [] { "added", "deleted", "edited", "moved" };
foreach (string action in actions) foreach (string action in actions)
{ {
image = SparkleUIHelpers.GetImageSource("document-" + action + "-12"); image = SparkleUIHelpers.GetImageSource ("document-" + action + "-12");
file_path = Path.Combine(pixmaps_path, "document-" + action + "-12.png"); 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(); BitmapEncoder encoder = new PngBitmapEncoder ();
encoder.Frames.Add(BitmapFrame.Create(image)); encoder.Frames.Add (BitmapFrame.Create(image));
encoder.Save(stream); encoder.Save (stream);
} }
} }
} }
} }
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[ComVisible(true)]
public class SparkleScriptingObject
{
public void LinkClicked(string url)
{
Program.UI.EventLog.Controller.LinkClicked(url);
}
}
} }

View file

@ -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);
}
}
}

View file

@ -30,7 +30,8 @@
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<ApplicationIcon>Pixmaps\sparkleshare-app.ico</ApplicationIcon> <ApplicationIcon>Pixmaps\sparkleshare-app.ico</ApplicationIcon>
<ReleaseVersion /> <ReleaseVersion>
</ReleaseVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType> <DebugType>none</DebugType>
@ -79,7 +80,6 @@
<Compile Include="SparkleEventLogWindow.xaml.cs"> <Compile Include="SparkleEventLogWindow.xaml.cs">
<DependentUpon>SparkleEventLogWindow.xaml</DependentUpon> <DependentUpon>SparkleEventLogWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="SparkleScriptingObject.cs" />
<Compile Include="SparkleShortcut.cs" /> <Compile Include="SparkleShortcut.cs" />
<Compile Include="SparkleUI.cs" /> <Compile Include="SparkleUI.cs" />
<Compile Include="..\SparkleAboutController.cs" /> <Compile Include="..\SparkleAboutController.cs" />
@ -102,7 +102,6 @@
</Compile> </Compile>
<Compile Include="SparkleNotifyIcon.cs" /> <Compile Include="SparkleNotifyIcon.cs" />
<Compile Include="SparkleSpinner.cs" /> <Compile Include="SparkleSpinner.cs" />
<Compile Include="WPFChromeExtensions.cs" />
</ItemGroup> </ItemGroup>
<ProjectExtensions> <ProjectExtensions>
<MonoDevelop> <MonoDevelop>

View file

@ -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
{
/// <summary>
/// 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
/// </summary>
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));
}
}
}