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" />
<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.
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="sizingControlWidth" Grid.Column="0" Grid.Row="1" Visibility="Hidden" />
</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
{
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 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);
/// <summary>
/// Initializes a new instance of the <see cref="SparkleEventLogWindow"/> class.
/// </summary>
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 ();
}));
}
/// <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)
{
this.Controller.WindowClosed ();
Controller.WindowClosed ();
cancel_event_args.Cancel = true;
}
/// <summary>
/// Updates the content of the webbrowser.
/// </summary>
/// <param name="html">The HTML.</param>
private void UpdateContent (string html)
{
string pixmaps_path = Path.Combine (SparkleLib.SparkleConfig.DefaultConfig.TmpPath, "Pixmaps");
pixmaps_path = pixmaps_path.Replace ("\\", "/");
html = html.Replace("<a href=", "<a class='windows' href=");
html = html.Replace("<!-- $body-font-family -->", "'Segoe UI', sans-serif");
html = html.Replace("<!-- $day-entry-header-font-size -->", "13px");
html = html.Replace("<!-- $body-font-size -->", "12px");
html = html.Replace("<!-- $secondary-font-color -->", "#bbb");
html = html.Replace("<!-- $small-color -->", "#ddd");
html = html.Replace("<!-- $small-font-size -->", "90%");
html = html.Replace("<!-- $day-entry-header-background-color -->", "#f5f5f5");
html = html.Replace("<!-- $a-color -->", "#0085cf");
html = html.Replace("<!-- $a-hover-color -->", "#009ff8");
html = html.Replace("<!-- $pixmaps-path -->", pixmaps_path);
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-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 ("<a href=", "<a class='windows' href=");
html = html.Replace ("<!-- $body-font-family -->", "'Segoe UI', sans-serif");
html = html.Replace ("<!-- $day-entry-header-font-size -->", "13px");
html = html.Replace ("<!-- $body-font-size -->", "12px");
html = html.Replace ("<!-- $secondary-font-color -->", "#bbb");
html = html.Replace ("<!-- $small-color -->", "#ddd");
html = html.Replace ("<!-- $small-font-size -->", "90%");
html = html.Replace ("<!-- $day-entry-header-background-color -->", "#f5f5f5");
html = html.Replace ("<!-- $a-color -->", "#0085cf");
html = html.Replace ("<!-- $a-hover-color -->", "#009ff8");
html = html.Replace ("<!-- $pixmaps-path -->", pixmaps_path);
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-deleted-background-image -->", pixmaps_path + "/document-deleted-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.NavigateToString (html);
}
/// <summary>
/// Updates the combobox-items.
/// </summary>
/// <param name="folders">The folders.</param>
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;
});
};
}
/// <summary>
/// Writes the images from the pixel-map to the temp-folder.
/// </summary>
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);
}
}
}

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