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 POTFILES
SparkleLib/windows/GlobalAssemblyInfoGit.cs SparkleLib/windows/GlobalAssemblyInfoGit.cs
intltool-* intltool-*
SparkleShare/data
configure configure
config.guess config.guess
config.h config.h

View file

@ -18,19 +18,18 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Windows.Forms; using System.Windows;
using System.Windows.Controls;
namespace SparkleShare { namespace SparkleShare {
public class SparkleAbout : Form { public class SparkleAbout : Window {
public SparkleAboutController Controller = new SparkleAboutController (); public SparkleAboutController Controller = new SparkleAboutController ();
private IContainer components;
private Label version; private Label version;
private Label copyright; private Label copyright;
private Label updates; private Label updates;
@ -45,61 +44,48 @@ namespace SparkleShare {
public SparkleAbout () 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; //BackgroundImage = Icons.about;
Height = 300;
SizeGripStyle = SizeGripStyle.Hide; Width = 600;
StartPosition = FormStartPosition.CenterScreen; //Closing
// += Close;
FormClosing += Close;
CreateHandle ();
CreateAbout (); CreateAbout ();
Controller.ShowWindowEvent += delegate { Controller.ShowWindowEvent += delegate {
this.version.Invoke ((Action) delegate { Dispatcher.Invoke ((Action) delegate {
Show (); Show ();
BringToFront (); BringIntoView ();
}); });
}; };
Controller.HideWindowEvent += delegate { Controller.HideWindowEvent += delegate {
Invoke ((Action) delegate { Dispatcher.Invoke ((Action) delegate {
Hide (); Hide ();
}); });
}; };
Controller.NewVersionEvent += delegate (string new_version) { Controller.NewVersionEvent += delegate (string new_version) {
Invoke ((Action) delegate { Dispatcher.Invoke ((Action) delegate {
this.updates.Text = "A newer version (" + new_version + ") is available!"; this.updates.Content = "A newer version (" + new_version + ") is available!";
}); });
}; };
Controller.VersionUpToDateEvent += delegate { Controller.VersionUpToDateEvent += delegate {
Invoke ((Action) delegate { Dispatcher.Invoke ((Action) delegate {
this.updates.Text = "You are running the latest version."; this.updates.Content = "You are running the latest version.";
}); });
}; };
Controller.CheckingForNewVersionEvent += delegate { Controller.CheckingForNewVersionEvent += delegate {
Invoke ((Action) delegate { Dispatcher.Invoke ((Action) delegate {
this.updates.Text = "Checking for updates..."; this.updates.Content = "Checking for updates...";
}); });
}; };
} }
@ -107,59 +93,47 @@ namespace SparkleShare {
private void CreateAbout () private void CreateAbout ()
{ {
ComponentResourceManager resources =
new ComponentResourceManager (typeof (SparkleAbout));
SuspendLayout ();
this.version = new Label () { this.version = new Label () {
AutoSize = true,
BackColor = Color.Transparent,
ForeColor = Color.LightGray, Content = "version " + Controller.RunningVersion
Location = new Point (302, 102),
Size = new Size (34, 13),
Text = "version " + Controller.RunningVersion
}; };
this.version.SetValue(Canvas.LeftProperty, 302.0);
this.version.SetValue(Canvas.TopProperty, 102.0);
this.updates = new Label () { this.updates = new Label () {
AutoSize = true, Content = "Checking for updates..."
BackColor = Color.Transparent,
ForeColor = Color.White,
Location = new Point (302, 89),
Size = new Size (106, 13),
Text = "Checking for updates..."
}; };
this.version.SetValue(Canvas.LeftProperty, 302.0);
this.version.SetValue(Canvas.TopProperty, 98.0);
this.copyright = new Label () { this.copyright = new Label () {
BackColor = Color.Transparent, Content = "Copyright © 2010" + DateTime.Now.Year + " Hylke Bons and others.\n" +
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" +
"SparkleShare is Free and Open Source Software. You are free to use, modify, " + "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." "and redistribute it under the GNU General Public License version 3 or later."
}; };
Controls.Add (this.version); this.version.SetValue(Canvas.LeftProperty, 302.0);
Controls.Add (this.updates); this.version.SetValue(Canvas.TopProperty, 84.0);
Controls.Add (this.copyright); AddVisualChild (this.version);
Button b = new Button ();
ResumeLayout (false); b.Content = "FFF";
PerformLayout ();
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, Clos)
}
private void Close (object sender, FormClosingEventArgs args)
{ {
if (args.CloseReason != CloseReason.ApplicationExitCall && if (args.CloseReason != CloseReason.ApplicationExitCall &&
args.CloseReason != CloseReason.TaskManagerClosing && args.CloseReason != CloseReason.TaskManagerClosing &&
@ -168,6 +142,6 @@ namespace SparkleShare {
Controller.WindowClosed (); Controller.WindowClosed ();
args.Cancel = true; args.Cancel = true;
} }
} }*/
} }
} }

View file

@ -53,30 +53,31 @@ namespace SparkleShare {
Program.TranslateWinForm (this); Program.TranslateWinForm (this);
this.Icon = Icons.sparkleshare; // this.Icon = Icons.sparkleshare;
this.change_sets = Program.Controller.GetLog (null); this.change_sets = Program.Controller.GetLog (null);
GenerateHTML (); GenerateHTML ();
_browserControl = new CefWebBrowser ("application://sparkleshare/eventlog"); _browserControl = new CefWebBrowser ("application://sparkleshare/eventlog");
_browserControl.Dock = DockStyle.Fill; _browserControl.Dock = DockStyle.Fill;
//_browserControl.PropertyChanged += HandleBrowserPropertyChanged; //_browserControl.PropertyChanged += HandleBrowserPropertyChanged;
//_browserControl.ConsoleMessage += HandleConsoleMessage; //_browserControl.ConsoleMessage += HandleConsoleMessage;
_browserControl.BeforeResourceLoadHandler = this; _browserControl.BeforeResourceLoadHandler = this;
WebViewPanel.Controls.Add (_browserControl); WebViewPanel.Controls.Add (_browserControl);
UpdateChooser (); UpdateChooser ();
} }
public void UpdateChooser () public void UpdateChooser ()
{ {
this.combo_box.Items.Add (_ ("All Projects")); this.combo_box.Items.Add (_ ("All Projects"));
this.combo_box.Items.Add (""); this.combo_box.Items.Add ("");
foreach (string folder_name in Program.Controller.Folders) foreach (string folder_name in Program.Controller.Folders)
this.combo_box.Items.Add (folder_name); 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> </PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <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"> <Reference Include="Gettext.Cs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\tools\gettext-cs-utils\Gettext.CsUtils\Core\Gettext.Cs\bin\Release\Gettext.Cs.dll</HintPath> <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.Windows.Forms" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Xml" /> <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>
<ItemGroup> <ItemGroup>
<Compile Include="..\..\SparkleLib\windows\GlobalAssemblyInfo.cs"> <Compile Include="..\..\SparkleLib\windows\GlobalAssemblyInfo.cs">
@ -115,7 +118,6 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="..\SparkleSetupController.cs" /> <Compile Include="..\SparkleSetupController.cs" />
<Compile Include="SparkleUI.cs" /> <Compile Include="SparkleUI.cs" />
<Compile Include="..\SparkleAboutController.cs" /> <Compile Include="..\SparkleAboutController.cs" />

View file

@ -21,7 +21,9 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SparkleLib; using SparkleLib;
using System.Windows.Forms; using WinForms = System.Windows.Forms;
using System.Windows.Controls;
using System.Windows;
namespace SparkleShare { namespace SparkleShare {
@ -30,13 +32,12 @@ namespace SparkleShare {
public SparkleStatusIconController Controller = new SparkleStatusIconController(); public SparkleStatusIconController Controller = new SparkleStatusIconController();
private Timer Animation; private WinForms.Timer Animation;
private Bitmap [] AnimationFrames; private Bitmap [] AnimationFrames;
private int FrameNumber; private int FrameNumber;
private string StateText; private string StateText;
private ToolStripItem status_menu_item; private WinForms.NotifyIcon status_icon;
private NotifyIcon status_icon;
// Short alias for the translations // Short alias for the translations
public static string _ (string s) 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 (); AnimationFrames = CreateAnimationFrames ();
Animation = CreateAnimation (); Animation = CreateAnimation ();
this.status_icon = new NotifyIcon (); this.status_icon = new WinForms.NotifyIcon ();
status_icon.Text = "SparkleShare"; status_icon.Text = "SparkleShare";
status_icon.Icon = Icons.sparkleshare; status_icon.Icon = Icons.sparkleshare;
status_icon.Visible = true; status_icon.Visible = true;
this.status_icon.MouseDown += new WinForms.MouseEventHandler(notifier_MouseDown);
CreateMenu (); CreateMenu ();
SetNormalState (); SetNormalState ();
@ -108,11 +164,11 @@ namespace SparkleShare {
// Creates the Animation that handles the syncing animation // Creates the Animation that handles the syncing animation
private Timer CreateAnimation () private WinForms.Timer CreateAnimation ()
{ {
FrameNumber = 0; FrameNumber = 0;
Timer Animation = new Timer () { WinForms.Timer Animation = new WinForms.Timer () {
Interval = 35 Interval = 35
}; };
@ -135,7 +191,7 @@ namespace SparkleShare {
// user clicks the status icon // user clicks the status icon
public void CreateMenu () public void CreateMenu ()
{ {
ContextMenuStrip Menu = new ContextMenuStrip (); /* ContextMenuStrip Menu = new ContextMenuStrip ();
// The menu item showing the status and size of the SparkleShare folder // The menu item showing the status and size of the SparkleShare folder
status_menu_item = new ToolStripLabel (StateText); status_menu_item = new ToolStripLabel (StateText);
@ -252,7 +308,11 @@ namespace SparkleShare {
Menu.Items.Add (quit_item); Menu.Items.Add (quit_item);
status_icon.ContextMenuStrip = Menu; status_icon.ContextMenuStrip = Menu;
} */
// ShowBalloon ("Hi!", "...", null);
}
public void ShowBalloon (string title, string subtext, string image_path) public void ShowBalloon (string title, string subtext, string image_path)
@ -261,7 +321,7 @@ namespace SparkleShare {
status_icon.BalloonTipText = title; status_icon.BalloonTipText = title;
status_icon.BalloonTipText = subtext; status_icon.BalloonTipText = subtext;
status_icon.BalloonTipIcon = ToolTipIcon.None; status_icon.BalloonTipIcon = WinForms.ToolTipIcon.None;
status_icon.ShowBalloonTip (5 * 1000); status_icon.ShowBalloonTip (5 * 1000);
} }
@ -269,7 +329,7 @@ namespace SparkleShare {
public void UpdateMenu () 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 class ControlExtention {
public static void SafeInvoke (this Control ui_element, public static void SafeInvoke (this WinForms.Control ui_element,
Action updater, bool force_synchronous) Action updater, bool force_synchronous)
{ {
if (ui_element == null) 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); ui_element.SafeInvoke (updater, false);
} }

View file

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