event log: Move more logic to controller and fix opening links with spaces

This commit is contained in:
Hylke Bons 2011-11-17 12:17:19 +00:00
parent 2f6c90420e
commit 977c1694c3
6 changed files with 59 additions and 60 deletions

View file

@ -189,6 +189,13 @@ namespace SparkleShare {
}
public override void OpenFile (string url)
{
url = url.Replace ("%20", " ");
NSWorkspace.SharedWorkspace.OpenFile (url);
}
new public void Quit ()
{
this.watcher.Dispose ();

View file

@ -18,7 +18,6 @@
using System;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using MonoMac.Foundation;
@ -194,30 +193,7 @@ namespace SparkleShare {
public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info,
NSUrlRequest request, WebFrame frame, NSObject decision_token)
{
string url = request.Url.ToString ();
if (url.StartsWith (Path.VolumeSeparatorChar.ToString ())) {
string file_path = request.Url.ToString ();
file_path = file_path.Replace ("%20", " ");
NSWorkspace.SharedWorkspace.OpenFile (file_path);
} else {
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
Match match = regex.Match (url);
if (match.Success) {
string folder_name = match.Groups [1].Value;
string revision = match.Groups [2].Value;
string note = match.Groups [3].Value;
Thread thread = new Thread (new ThreadStart (delegate {
Program.Controller.AddNoteToFolder (folder_name, revision, note);
}));
thread.Start ();
}
}
SparkleEventLogController.LinkClicked (request.Url.ToString ());
}
}
}

View file

@ -217,5 +217,14 @@ namespace SparkleShare {
process.StartInfo.Arguments = "\"" + folder + "\"";
process.Start ();
}
public override void OpenFile (string url)
{
Process process = new Process ();
process.StartInfo.FileName = "xdg-open";
process.StartInfo.Arguments = url.Replace (" ", "%20");
process.Start ();
}
}
}

View file

@ -531,6 +531,9 @@ namespace SparkleShare {
// Opens the SparkleShare folder or an (optional) subfolder
public abstract void OpenSparkleShareFolder (string subfolder);
// Opens a file with the appropriate application
public abstract void OpenFile (string url);
// Fires events for the current syncing state
public void UpdateState ()

View file

@ -65,44 +65,22 @@ namespace SparkleShare {
this.content_wrapper = new EventBox ();
this.scrolled_window = new ScrolledWindow ();
this.web_view = new WebView () {
Editable = false
};
this.web_view = new WebView () {
Editable = false
};
this.web_view.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
this.link_status = args.Link;
};
this.web_view.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
this.link_status = args.Link;
};
this.web_view.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
if (args.Request.Uri == this.link_status) {
// TODO: controller
Process process = new Process ();
process.StartInfo.FileName = "xdg-open";
process.StartInfo.Arguments = args.Request.Uri.Replace (" ", "\\ "); // Escape space-characters
process.Start ();
this.web_view.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
if (args.Request.Uri == this.link_status)
Controller.LinkClicked (args.Request.Uri);
} else {
//TODO: controller
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
Match match = regex.Match (args.Request.Uri);
if (match.Success) {
string folder_name = match.Groups [1].Value;
string revision = match.Groups [2].Value;
string note = match.Groups [3].Value;
Thread thread = new Thread (new ThreadStart (delegate {
Program.Controller.AddNoteToFolder (folder_name, revision, note);
}));
thread.Start ();
}
}
// Don't follow HREFs (as this would cause a page refresh)
if (!args.Request.Uri.Equals ("file:"))
args.RetVal = 1;
};
// Don't follow HREFs (as this would cause a page refresh)
if (!args.Request.Uri.Equals ("file:"))
args.RetVal = 1;
};
this.scrolled_window.Add (this.web_view);
this.content_wrapper.Add (this.spinner);

View file

@ -18,6 +18,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using SparkleLib;
@ -115,5 +117,29 @@ namespace SparkleShare {
UpdateContentEvent (HTML);
};
}
public static void LinkClicked (string url)
{
if (url.StartsWith (Path.VolumeSeparatorChar.ToString ())) {
Program.Controller.OpenFile (url);
} else {
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
Match match = regex.Match (url);
if (match.Success) {
string folder_name = match.Groups [1].Value;
string revision = match.Groups [2].Value;
string note = match.Groups [3].Value;
Thread thread = new Thread (new ThreadStart (delegate {
Program.Controller.AddNoteToFolder (folder_name, revision, note);
}));
thread.Start ();
}
}
}
}
}