windows: Start porting work from WinForms to WPF.

This commit is contained in:
Hylke Bons 2012-03-04 02:36:23 +00:00
parent 6ddcc7e16c
commit 5bd86cd790
6 changed files with 137 additions and 99 deletions

1
.gitignore vendored
View file

@ -16,6 +16,7 @@ Makefile
POTFILES
SparkleLib/windows/GlobalAssemblyInfoGit.cs
intltool-*
SparkleShare/data
configure
config.guess
config.h

View file

@ -18,19 +18,18 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Forms;
using System.Windows;
using System.Windows.Controls;
namespace SparkleShare {
public class SparkleAbout : Form {
public class SparkleAbout : Window {
public SparkleAboutController Controller = new SparkleAboutController ();
private IContainer components;
private Label version;
private Label copyright;
private Label updates;
@ -45,61 +44,48 @@ namespace SparkleShare {
public SparkleAbout ()
{
Name = "SparkleAbout";
Title = "About SparkleShare";
// Icon = Icons.sparkleshare;
Text = "About SparkleShare";
Icon = Icons.sparkleshare;
MaximizeBox = false;
MinimizeBox = false;
BackgroundImage = Icons.about;
ClientSize = BackgroundImage.Size;
AutoScaleDimensions = new SizeF (6F, 13F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size (640, 260);
MaximumSize = Size;
MinimumSize = Size;
FormBorderStyle = FormBorderStyle.FixedDialog;
SizeGripStyle = SizeGripStyle.Hide;
StartPosition = FormStartPosition.CenterScreen;
FormClosing += Close;
CreateHandle ();
//BackgroundImage = Icons.about;
Height = 300;
Width = 600;
//Closing
// += Close;
CreateAbout ();
Controller.ShowWindowEvent += delegate {
this.version.Invoke ((Action) delegate {
Dispatcher.Invoke ((Action) delegate {
Show ();
BringToFront ();
BringIntoView ();
});
};
Controller.HideWindowEvent += delegate {
Invoke ((Action) delegate {
Dispatcher.Invoke ((Action) delegate {
Hide ();
});
};
Controller.NewVersionEvent += delegate (string new_version) {
Invoke ((Action) delegate {
this.updates.Text = "A newer version (" + new_version + ") is available!";
Dispatcher.Invoke ((Action) delegate {
this.updates.Content = "A newer version (" + new_version + ") is available!";
});
};
Controller.VersionUpToDateEvent += delegate {
Invoke ((Action) delegate {
this.updates.Text = "You are running the latest version.";
Dispatcher.Invoke ((Action) delegate {
this.updates.Content = "You are running the latest version.";
});
};
Controller.CheckingForNewVersionEvent += delegate {
Invoke ((Action) delegate {
this.updates.Text = "Checking for updates...";
Dispatcher.Invoke ((Action) delegate {
this.updates.Content = "Checking for updates...";
});
};
}
@ -107,59 +93,47 @@ namespace SparkleShare {
private void CreateAbout ()
{
ComponentResourceManager resources =
new ComponentResourceManager (typeof (SparkleAbout));
SuspendLayout ();
this.version = new Label () {
AutoSize = true,
BackColor = Color.Transparent,
ForeColor = Color.LightGray,
Location = new Point (302, 102),
Size = new Size (34, 13),
Text = "version " + Controller.RunningVersion
Content = "version " + Controller.RunningVersion
};
this.version.SetValue(Canvas.LeftProperty, 302.0);
this.version.SetValue(Canvas.TopProperty, 102.0);
this.updates = new Label () {
AutoSize = true,
BackColor = Color.Transparent,
ForeColor = Color.White,
Location = new Point (302, 89),
Size = new Size (106, 13),
Text = "Checking for updates..."
Content = "Checking for updates..."
};
this.version.SetValue(Canvas.LeftProperty, 302.0);
this.version.SetValue(Canvas.TopProperty, 98.0);
this.copyright = new Label () {
BackColor = Color.Transparent,
Font = new Font ("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte) (0))),
ForeColor = Color.White,
Location = new Point (302, 135),
Size = new Size (298, 84),
Text = "Copyright © 2010" + DateTime.Now.Year + " Hylke Bons and others.\n" +
Content = "Copyright © 2010" + DateTime.Now.Year + " Hylke Bons and others.\n" +
"SparkleShare is Free and Open Source Software. You are free to use, modify, " +
"and redistribute it under the GNU General Public License version 3 or later."
};
Controls.Add (this.version);
Controls.Add (this.updates);
Controls.Add (this.copyright);
ResumeLayout (false);
PerformLayout ();
this.version.SetValue(Canvas.LeftProperty, 302.0);
this.version.SetValue(Canvas.TopProperty, 84.0);
AddVisualChild (this.version);
Button b = new Button ();
b.Content = "FFF";
Content = this.copyright;
//AddChild(this.version);
//AddChild(this.updates);
//AddChild(this.copyright);
Show ();
}
protected override void Dispose (bool disposing) {
if (disposing && (components != null))
components.Dispose ();
/*
base.Dispose (disposing);
}
private void Close (object sender, FormClosingEventArgs args)
private void Close (object sender, Clos)
{
if (args.CloseReason != CloseReason.ApplicationExitCall &&
args.CloseReason != CloseReason.TaskManagerClosing &&
@ -168,6 +142,6 @@ namespace SparkleShare {
Controller.WindowClosed ();
args.Cancel = true;
}
}
}*/
}
}

View file

@ -53,30 +53,31 @@ namespace SparkleShare {
Program.TranslateWinForm (this);
this.Icon = Icons.sparkleshare;
// this.Icon = Icons.sparkleshare;
this.change_sets = Program.Controller.GetLog (null);
GenerateHTML ();
_browserControl = new CefWebBrowser ("application://sparkleshare/eventlog");
_browserControl.Dock = DockStyle.Fill;
//_browserControl.PropertyChanged += HandleBrowserPropertyChanged;
//_browserControl.ConsoleMessage += HandleConsoleMessage;
_browserControl.BeforeResourceLoadHandler = this;
WebViewPanel.Controls.Add (_browserControl);
UpdateChooser ();
}
public void UpdateChooser ()
{
this.combo_box.Items.Add (_ ("All Projects"));
this.combo_box.Items.Add ("");
foreach (string folder_name in Program.Controller.Folders)
this.combo_box.Items.Add (folder_name);
this.combo_box.SelectedItem = this.combo_box.Items[0];
//this.combo_box.SelectedItem = this.combo_box.Items[0];
}

View file

@ -54,9 +54,6 @@
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Reference Include="CefSharp, Version=0.3.4006.34354, Culture=neutral, processorArchitecture=x86">
<HintPath>..\..\bin\CefSharp.dll</HintPath>
</Reference>
<Reference Include="Gettext.Cs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\tools\gettext-cs-utils\Gettext.CsUtils\Core\Gettext.Cs\bin\Release\Gettext.Cs.dll</HintPath>
@ -70,6 +67,12 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Configuration" />
<Reference Include="System.Xml" />
<Reference Include="CefSharp, Version=0.3.4006.34354, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\bin\CefSharp.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\SparkleLib\windows\GlobalAssemblyInfo.cs">
@ -115,7 +118,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="..\SparkleSetupController.cs" />
<Compile Include="SparkleUI.cs" />
<Compile Include="..\SparkleAboutController.cs" />

View file

@ -21,7 +21,9 @@ using System.IO;
using System.Runtime.InteropServices;
using SparkleLib;
using System.Windows.Forms;
using WinForms = System.Windows.Forms;
using System.Windows.Controls;
using System.Windows;
namespace SparkleShare {
@ -30,13 +32,12 @@ namespace SparkleShare {
public SparkleStatusIconController Controller = new SparkleStatusIconController();
private Timer Animation;
private WinForms.Timer Animation;
private Bitmap [] AnimationFrames;
private int FrameNumber;
private string StateText;
private ToolStripItem status_menu_item;
private NotifyIcon status_icon;
private WinForms.NotifyIcon status_icon;
// Short alias for the translations
public static string _ (string s)
@ -45,15 +46,70 @@ namespace SparkleShare {
}
public SparkleStatusIcon ()
void notifier_MouseDown(object sender, WinForms.MouseEventArgs e)
{
ContextMenu menu = new ContextMenu ();
MenuItem item = new MenuItem () {Header = " SparkleShare"};
MenuItem item2 = new MenuItem () {Header = " Add Hosted Project..."};
MenuItem item3 = new MenuItem () {Header = " View Recent Changes..."};
MenuItem item4 = new MenuItem () {Header = " Turn Notifications Off"};
MenuItem item5 = new MenuItem () {Header = " About SparkleShare"};
MenuItem item6 = new MenuItem () {Header = " Quit"};
menu.Items.Add (item);
menu.Items.Add (new Separator ());menu.Items.Add (item2);
menu.Items.Add (new Separator ());
menu.Items.Add (item3);
menu.Items.Add (item4);
menu.Items.Add (new Separator ());
menu.Items.Add (item5);
menu.Items.Add (new Separator ());
menu.Items.Add (item6);
menu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
menu.IsOpen = true;
menu.IsHitTestVisible=true;
Window w = new Window ();
w.Title = "test";
w.Show ();
w.Height = 300;
w.Width = 300;
w.BringIntoView ();
}
public SparkleStatusIcon ()
{
AnimationFrames = CreateAnimationFrames ();
Animation = CreateAnimation ();
this.status_icon = new NotifyIcon ();
this.status_icon = new WinForms.NotifyIcon ();
status_icon.Text = "SparkleShare";
status_icon.Icon = Icons.sparkleshare;
status_icon.Visible = true;
this.status_icon.MouseDown += new WinForms.MouseEventHandler(notifier_MouseDown);
CreateMenu ();
SetNormalState ();
@ -108,11 +164,11 @@ namespace SparkleShare {
// Creates the Animation that handles the syncing animation
private Timer CreateAnimation ()
private WinForms.Timer CreateAnimation ()
{
FrameNumber = 0;
Timer Animation = new Timer () {
WinForms.Timer Animation = new WinForms.Timer () {
Interval = 35
};
@ -135,7 +191,7 @@ namespace SparkleShare {
// user clicks the status icon
public void CreateMenu ()
{
ContextMenuStrip Menu = new ContextMenuStrip ();
/* ContextMenuStrip Menu = new ContextMenuStrip ();
// The menu item showing the status and size of the SparkleShare folder
status_menu_item = new ToolStripLabel (StateText);
@ -252,7 +308,11 @@ namespace SparkleShare {
Menu.Items.Add (quit_item);
status_icon.ContextMenuStrip = Menu;
}
*/
// ShowBalloon ("Hi!", "...", null);
}
public void ShowBalloon (string title, string subtext, string image_path)
@ -261,7 +321,7 @@ namespace SparkleShare {
status_icon.BalloonTipText = title;
status_icon.BalloonTipText = subtext;
status_icon.BalloonTipIcon = ToolTipIcon.None;
status_icon.BalloonTipIcon = WinForms.ToolTipIcon.None;
status_icon.ShowBalloonTip (5 * 1000);
}
@ -269,7 +329,7 @@ namespace SparkleShare {
public void UpdateMenu ()
{
status_menu_item.Text=StateText;
// status_menu_item.Text=StateText;
}
@ -350,7 +410,7 @@ namespace SparkleShare {
public static class ControlExtention {
public static void SafeInvoke (this Control ui_element,
public static void SafeInvoke (this WinForms.Control ui_element,
Action updater, bool force_synchronous)
{
if (ui_element == null)
@ -377,7 +437,7 @@ namespace SparkleShare {
}
public static void SafeInvoke (this Control ui_element, Action updater)
public static void SafeInvoke (this WinForms.Control ui_element, Action updater)
{
ui_element.SafeInvoke (updater, false);
}

View file

@ -64,7 +64,7 @@ namespace SparkleShare {
#endif
Setup = new SparkleSetup ();
//EventLog = new SparkleEventLog ();
EventLog = new SparkleEventLog ();
About = new SparkleAbout ();
Bubbles = new SparkleBubbles ();
StatusIcon = new SparkleStatusIcon ();