event log: Move more logic to controller and fix opening links with spaces
This commit is contained in:
parent
2f6c90420e
commit
977c1694c3
|
@ -189,6 +189,13 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void OpenFile (string url)
|
||||||
|
{
|
||||||
|
url = url.Replace ("%20", " ");
|
||||||
|
NSWorkspace.SharedWorkspace.OpenFile (url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
new public void Quit ()
|
new public void Quit ()
|
||||||
{
|
{
|
||||||
this.watcher.Dispose ();
|
this.watcher.Dispose ();
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
using MonoMac.Foundation;
|
using MonoMac.Foundation;
|
||||||
|
@ -194,30 +193,7 @@ namespace SparkleShare {
|
||||||
public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info,
|
public override void DecidePolicyForNavigation (WebView web_view, NSDictionary action_info,
|
||||||
NSUrlRequest request, WebFrame frame, NSObject decision_token)
|
NSUrlRequest request, WebFrame frame, NSObject decision_token)
|
||||||
{
|
{
|
||||||
string url = request.Url.ToString ();
|
SparkleEventLogController.LinkClicked (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 ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,5 +217,14 @@ namespace SparkleShare {
|
||||||
process.StartInfo.Arguments = "\"" + folder + "\"";
|
process.StartInfo.Arguments = "\"" + folder + "\"";
|
||||||
process.Start ();
|
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 ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -531,6 +531,9 @@ namespace SparkleShare {
|
||||||
// Opens the SparkleShare folder or an (optional) subfolder
|
// Opens the SparkleShare folder or an (optional) subfolder
|
||||||
public abstract void OpenSparkleShareFolder (string 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
|
// Fires events for the current syncing state
|
||||||
public void UpdateState ()
|
public void UpdateState ()
|
||||||
|
|
|
@ -65,44 +65,22 @@ namespace SparkleShare {
|
||||||
this.content_wrapper = new EventBox ();
|
this.content_wrapper = new EventBox ();
|
||||||
this.scrolled_window = new ScrolledWindow ();
|
this.scrolled_window = new ScrolledWindow ();
|
||||||
|
|
||||||
this.web_view = new WebView () {
|
this.web_view = new WebView () {
|
||||||
Editable = false
|
Editable = false
|
||||||
};
|
};
|
||||||
|
|
||||||
this.web_view.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
|
this.web_view.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
|
||||||
this.link_status = args.Link;
|
this.link_status = args.Link;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.web_view.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
|
this.web_view.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
|
||||||
if (args.Request.Uri == this.link_status) {
|
if (args.Request.Uri == this.link_status)
|
||||||
// TODO: controller
|
Controller.LinkClicked (args.Request.Uri);
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.FileName = "xdg-open";
|
|
||||||
process.StartInfo.Arguments = args.Request.Uri.Replace (" ", "\\ "); // Escape space-characters
|
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
} else {
|
// Don't follow HREFs (as this would cause a page refresh)
|
||||||
//TODO: controller
|
if (!args.Request.Uri.Equals ("file:"))
|
||||||
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
|
args.RetVal = 1;
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.scrolled_window.Add (this.web_view);
|
this.scrolled_window.Add (this.web_view);
|
||||||
this.content_wrapper.Add (this.spinner);
|
this.content_wrapper.Add (this.spinner);
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
using SparkleLib;
|
using SparkleLib;
|
||||||
|
@ -115,5 +117,29 @@ namespace SparkleShare {
|
||||||
UpdateContentEvent (HTML);
|
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 ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue