From 34a9ece93900334a0a189da84da532f404164d6a Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 16 Oct 2012 21:51:53 +0100 Subject: [PATCH] history: implement windows save dialog --- SparkleShare/Common/HTML/event-log.html | 18 ++++--- SparkleShare/SparkleEventLogController.cs | 58 +++++++++++------------ SparkleShare/Windows/SparkleEventLog.cs | 54 +++++++++++++++++---- 3 files changed, 82 insertions(+), 48 deletions(-) diff --git a/SparkleShare/Common/HTML/event-log.html b/SparkleShare/Common/HTML/event-log.html index 9df3428d..302dec08 100755 --- a/SparkleShare/Common/HTML/event-log.html +++ b/SparkleShare/Common/HTML/event-log.html @@ -10,8 +10,9 @@ $('dl dd:nth-child(-n+10)').css('display', 'block'); $('.day-entry-content .event-entry:last-child').css('border', 'none'); - $('dd a.windows').click(function () { + $('a').click(function (event) { window.external.LinkClicked($(this).attr("href")); + event.preventDefault(); }); // Update the Today and Yesterday labels after midnight @@ -26,7 +27,7 @@ } }, 60 * 1000); - // Hide the 'Show all' link when there are less than 10 events + // Hide the 'Show all' link when there are fewer than 10 events $('.show').each (function () { var entry_count = $(this).parent ().find ('dl').children ().length; @@ -124,7 +125,6 @@ border-bottom: 1px #ddd solid; background-repeat: no-repeat; background-position: 36px 24px; - min-height: 100px; } .event-user-name { @@ -166,34 +166,32 @@ } table { - padding: 18px 32px; width: 100%; } + .table-wrapper { + padding: 64px 32px; + } + td { padding: 0; margin: 0; } td.name { - width: 45%; font-weight: bold; + width: 45%; } td.time { - font-size: ; color: ; padding-right: 9px; - width: 20px; - padding-top: 2px; } td.date { - font-size: ; color: ; text-align: right; padding-right: 6px; - padding-top: 2px; } td.restore { diff --git a/SparkleShare/SparkleEventLogController.cs b/SparkleShare/SparkleEventLogController.cs index 1c90753d..7784c638 100755 --- a/SparkleShare/SparkleEventLogController.cs +++ b/SparkleShare/SparkleEventLogController.cs @@ -224,6 +224,8 @@ namespace SparkleShare { public void LinkClicked (string url) { + + url = url.Replace ("%20", " "); if (url.StartsWith ("file://") || @@ -256,7 +258,6 @@ namespace SparkleShare { Path.GetDirectoryName (this.restore_revision_info.FilePath)); ShowSaveDialogEvent (file_name, target_folder_path); - } } else if (url.StartsWith ("back://")) { @@ -275,31 +276,29 @@ namespace SparkleShare { string folder = url.Replace ("history://", "").Split ("/".ToCharArray ()) [0]; string file_path = url.Replace ("history://" + folder + "/", ""); - SparkleRepoBase repo; + foreach (SparkleRepoBase repo in Program.Controller.Repositories) { + if (!repo.Name.Equals (folder)) + continue; - foreach (SparkleRepoBase test_repo in Program.Controller.Repositories) { - if (test_repo.Name.Equals (folder)) { - repo = test_repo; - break; - } + new Thread (() => { + Stopwatch watch = new Stopwatch (); + watch.Start (); + + List change_sets = repo.GetChangeSets (file_path); + string html = GetHistoryHTMLLog (change_sets, file_path); + + watch.Stop (); + int delay = 500; + + if (watch.ElapsedMilliseconds < delay) + Thread.Sleep (delay - (int) watch.ElapsedMilliseconds); + + UpdateContentEvent (html); + + }).Start (); + + break; } - - new Thread (() => { - Stopwatch watch = new Stopwatch (); - watch.Start (); - - List change_sets = repo.GetChangeSets (file_path); - string html = GetHistoryHTMLLog (change_sets, file_path); - - watch.Stop (); - int delay = 500; - - if (watch.ElapsedMilliseconds < delay) - Thread.Sleep (delay - (int) watch.ElapsedMilliseconds); - - UpdateContentEvent (html); - - }).Start (); } } @@ -365,7 +364,7 @@ namespace SparkleShare { public string GetHistoryHTMLLog (List change_sets, string file_path) { - string html = "
« Back  |  "; + string html = "
« Back  |  "; if (change_sets.Count > 1) html += "Revisions for “"; @@ -373,7 +372,7 @@ namespace SparkleShare { html += "No revisions for “"; html += Path.GetFileName (file_path) + "”"; - html += "
"; + html += "
"; int count = 0; foreach (SparkleChangeSet change_set in change_sets) { @@ -405,9 +404,10 @@ namespace SparkleShare { count++; } - html += "
"; - - return Program.Controller.EventLogHTML.Replace ("", html); + html += "
"; + html = Program.Controller.EventLogHTML.Replace ("", html); + + return html.Replace ("", "1000000000000000000"); } diff --git a/SparkleShare/Windows/SparkleEventLog.cs b/SparkleShare/Windows/SparkleEventLog.cs index 5cb4268a..53cb2518 100644 --- a/SparkleShare/Windows/SparkleEventLog.cs +++ b/SparkleShare/Windows/SparkleEventLog.cs @@ -14,7 +14,6 @@ // 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.ComponentModel; using System.IO; @@ -26,6 +25,7 @@ using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; +using Microsoft.Win32; using Shapes = System.Windows.Shapes; namespace SparkleShare { @@ -50,7 +50,7 @@ namespace SparkleShare { ResizeMode = ResizeMode.NoResize; // TODO Background = new SolidColorBrush (Color.FromRgb (240, 240, 240)); AllowsTransparency = false; - Icon = SparkleUIHelpers.GetImageSource("sparkleshare-app", "ico"); + Icon = SparkleUIHelpers.GetImageSource ("sparkleshare-app", "ico"); int x = (int) (SystemParameters.PrimaryScreenWidth * 0.61); int y = (int) (SystemParameters.PrimaryScreenHeight * 0.5 - (Height * 0.5)); @@ -104,6 +104,8 @@ namespace SparkleShare { this.web_browser.ObjectForScripting = new SparkleScriptingObject (); + + spinner = new SparkleSpinner (22); // Disable annoying IE clicking sound @@ -177,6 +179,12 @@ namespace SparkleShare { }); }; + Controller.UpdateChooserEnablementEvent += delegate (bool enabled) { + Dispatcher.BeginInvoke ((Action) delegate { + this.combo_box.IsEnabled = enabled; + }); + }; + Controller.UpdateContentEvent += delegate (string html) { Dispatcher.BeginInvoke ((Action) delegate { UpdateContent (html); @@ -191,6 +199,25 @@ namespace SparkleShare { this.canvas.Children.Remove (this.web_browser); }); }; + + Controller.ShowSaveDialogEvent += delegate (string file_name, string target_folder_path) { + Dispatcher.BeginInvoke ((Action) delegate { + SaveFileDialog dialog = new SaveFileDialog () { + FileName = file_name, + InitialDirectory = target_folder_path, + Title = "Restore from History", + DefaultExt = "." + Path.GetExtension (file_name), + Filter = "All Files|*.*" + }; + + Nullable result = dialog.ShowDialog (this); + + if (result == true) + Controller.SaveDialogCompleted (dialog.FileName); + else + Controller.SaveDialogCancelled (); + }); + }; } @@ -262,6 +289,7 @@ namespace SparkleShare { 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"); @@ -282,9 +310,17 @@ namespace SparkleShare { Dispatcher.BeginInvoke ((Action) delegate { this.spinner.Stop (); - - this.web_browser.NavigateToString (html); - + this.web_browser.ObjectForScripting = new SparkleScriptingObject (); + //if (html != null) { + this.web_browser.NavigateToString (html); + SparkleLib.SparkleLogger.LogInfo ("FFF", ""+html); + //} + /* this.web_browser.Navigating += delegate(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e) { + Program.UI.EventLog.Controller.LinkClicked (e.Uri.ToString()); + if (e.Uri.ToString().StartsWith ("back://")) + e.Cancel = true; + + };*/ if (!this.canvas.Children.Contains (this.web_browser)) { this.canvas.Children.Add (this.web_browser); Canvas.SetLeft (this.web_browser, 0); @@ -322,8 +358,8 @@ namespace SparkleShare { string [] actions = new string [] {"added", "deleted", "edited", "moved"}; foreach (string action in actions) { - BitmapSource image = SparkleUIHelpers.GetImageSource ("document-" + action + "-12"); - string 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)) { @@ -345,8 +381,8 @@ 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); }