log: fix coding style and whitespace
This commit is contained in:
parent
9901ca56ba
commit
a38442caf6
|
@ -28,268 +28,237 @@ using WebKit;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleLog : Window {
|
public class SparkleLog : Window {
|
||||||
|
|
||||||
public readonly string LocalPath;
|
public readonly string LocalPath;
|
||||||
|
|
||||||
private ScrolledWindow ScrolledWindow;
|
private ScrolledWindow ScrolledWindow;
|
||||||
private MenuBar MenuBar;
|
private MenuBar MenuBar;
|
||||||
private WebView WebView;
|
private WebView WebView;
|
||||||
private string LinkStatus;
|
private string LinkStatus;
|
||||||
private SparkleSpinner Spinner;
|
private SparkleSpinner Spinner;
|
||||||
private string HTML;
|
private string HTML;
|
||||||
private EventBox LogContent;
|
private EventBox LogContent;
|
||||||
|
|
||||||
|
|
||||||
// Short alias for the translations
|
// Short alias for the translations
|
||||||
public static string _ (string s)
|
public static string _ (string s)
|
||||||
{
|
{
|
||||||
return Catalog.GetString (s);
|
return Catalog.GetString (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SparkleLog (string path) : base ("")
|
public SparkleLog (string path) : base ("")
|
||||||
{
|
{
|
||||||
|
LocalPath = path;
|
||||||
LocalPath = path;
|
|
||||||
|
string name = System.IO.Path.GetFileName (LocalPath);
|
||||||
string name = System.IO.Path.GetFileName (LocalPath);
|
SetSizeRequest (480, 640);
|
||||||
SetSizeRequest (480, 640);
|
|
||||||
|
|
||||||
Resizable = false;
|
Resizable = false;
|
||||||
|
|
||||||
BorderWidth = 0;
|
BorderWidth = 0;
|
||||||
SetPosition (WindowPosition.Center);
|
SetPosition (WindowPosition.Center);
|
||||||
|
|
||||||
// Open slightly off center for each consecutive window
|
// Open slightly off center for each consecutive window
|
||||||
if (SparkleUI.OpenLogs.Count > 0) {
|
if (SparkleUI.OpenLogs.Count > 0) {
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
GetPosition (out x, out y);
|
GetPosition (out x, out y);
|
||||||
Move (x + SparkleUI.OpenLogs.Count * 20, y + SparkleUI.OpenLogs.Count * 20);
|
Move (x + SparkleUI.OpenLogs.Count * 20, y + SparkleUI.OpenLogs.Count * 20);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TRANSLATORS: {0} is a folder name, and {1} is a server address
|
// TRANSLATORS: {0} is a folder name, and {1} is a server address
|
||||||
Title = String.Format(_("Events in ‘{0}’"), name);
|
Title = String.Format(_("Events in ‘{0}’"), name);
|
||||||
IconName = "folder-sparkleshare";
|
IconName = "folder-sparkleshare";
|
||||||
|
|
||||||
DeleteEvent += Close;
|
DeleteEvent += Close;
|
||||||
|
|
||||||
CreateEventLog ();
|
CreateEventLog ();
|
||||||
UpdateEventLog ();
|
UpdateEventLog ();
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void CreateEventLog () {
|
private void CreateEventLog ()
|
||||||
|
{
|
||||||
|
LogContent = new EventBox ();
|
||||||
|
VBox layout_vertical = new VBox (false, 0);
|
||||||
|
|
||||||
LogContent = new EventBox ();
|
ScrolledWindow = new ScrolledWindow ();
|
||||||
VBox layout_vertical = new VBox (false, 0);
|
|
||||||
|
|
||||||
ScrolledWindow = new ScrolledWindow ();
|
WebView = new WebView () {
|
||||||
|
Editable = false
|
||||||
|
};
|
||||||
|
|
||||||
WebView = new WebView () {
|
WebView.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
|
||||||
Editable = false
|
LinkStatus = args.Link;
|
||||||
};
|
};
|
||||||
|
|
||||||
WebView.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
|
// FIXME: Use the right event, waiting for newer webkit bindings
|
||||||
LinkStatus = args.Link;
|
WebView.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
|
||||||
};
|
if (args.Request.Uri == LinkStatus) {
|
||||||
|
Process process = new Process ();
|
||||||
WebView.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
|
process.StartInfo.FileName = "xdg-open";
|
||||||
|
process.StartInfo.Arguments = args.Request.Uri.Replace (" ", "\\ "); // Escape space-characters
|
||||||
if (args.Request.Uri == LinkStatus) {
|
process.Start ();
|
||||||
|
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.FileName = "xdg-open";
|
|
||||||
process.StartInfo.Arguments = args.Request.Uri.Replace (" ", "\\ "); // Escape space-characters
|
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
// FIXME: Use the right event, waiting for newer webkit bindings
|
|
||||||
|
|
||||||
UpdateEventLog ();
|
UpdateEventLog ();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
ScrolledWindow.AddWithViewport (WebView);
|
||||||
|
LogContent.Add (ScrolledWindow);
|
||||||
|
|
||||||
};
|
layout_vertical.PackStart (LogContent, true, true, 0);
|
||||||
|
|
||||||
ScrolledWindow.AddWithViewport (WebView);
|
HButtonBox dialog_buttons = new HButtonBox {
|
||||||
LogContent.Add (ScrolledWindow);
|
Layout = ButtonBoxStyle.Edge,
|
||||||
|
BorderWidth = 12
|
||||||
|
};
|
||||||
|
|
||||||
layout_vertical.PackStart (LogContent, true, true, 0);
|
Button open_folder_button = new Button (_("_Open Folder")) {
|
||||||
|
UseUnderline = true
|
||||||
|
};
|
||||||
HButtonBox dialog_buttons = new HButtonBox {
|
|
||||||
Layout = ButtonBoxStyle.Edge,
|
|
||||||
BorderWidth = 12
|
|
||||||
};
|
|
||||||
|
|
||||||
Button open_folder_button = new Button (_("_Open Folder")) {
|
|
||||||
UseUnderline = true
|
|
||||||
};
|
|
||||||
|
|
||||||
open_folder_button.Clicked += delegate (object o, EventArgs args) {
|
open_folder_button.Clicked += delegate (object o, EventArgs args) {
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.FileName = "xdg-open";
|
||||||
|
process.StartInfo.Arguments = LocalPath.Replace (" ", "\\ "); // Escape space-characters
|
||||||
|
process.Start ();
|
||||||
|
};
|
||||||
|
|
||||||
Process process = new Process ();
|
Button close_button = new Button (Stock.Close);
|
||||||
process.StartInfo.FileName = "xdg-open";
|
|
||||||
process.StartInfo.Arguments = LocalPath.Replace (" ", "\\ "); // Escape space-characters
|
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
};
|
close_button.Clicked += delegate {
|
||||||
|
HideAll ();
|
||||||
|
};
|
||||||
|
|
||||||
Button close_button = new Button (Stock.Close);
|
dialog_buttons.Add (open_folder_button);
|
||||||
|
dialog_buttons.Add (close_button);
|
||||||
|
|
||||||
close_button.Clicked += delegate {
|
// We have to hide the menubar somewhere...
|
||||||
HideAll ();
|
layout_vertical.PackStart (CreateShortcutsBar (), false, false, 0);
|
||||||
};
|
layout_vertical.PackStart (dialog_buttons, false, false, 0);
|
||||||
|
|
||||||
dialog_buttons.Add (open_folder_button);
|
Add (layout_vertical);
|
||||||
dialog_buttons.Add (close_button);
|
|
||||||
|
|
||||||
// We have to hide the menubar somewhere...
|
ShowAll ();
|
||||||
layout_vertical.PackStart (CreateShortcutsBar (), false, false, 0);
|
}
|
||||||
layout_vertical.PackStart (dialog_buttons, false, false, 0);
|
|
||||||
|
|
||||||
Add (layout_vertical);
|
|
||||||
|
|
||||||
ShowAll ();
|
|
||||||
|
|
||||||
|
|
||||||
|
public void UpdateEventLog ()
|
||||||
|
{
|
||||||
|
if (HTML == null) { // TODO: there may be a race condition here
|
||||||
|
LogContent.Remove (LogContent.Child);
|
||||||
|
Spinner = new SparkleSpinner (22);
|
||||||
|
LogContent.Add (Spinner);
|
||||||
|
LogContent.ShowAll ();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
Thread thread = new Thread (new ThreadStart (delegate {
|
||||||
|
GenerateHTML ();
|
||||||
|
AddHTML ();
|
||||||
|
}));
|
||||||
|
|
||||||
|
thread.Start ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void UpdateEventLog ()
|
private void GenerateHTML ()
|
||||||
{
|
{
|
||||||
|
HTML = SparkleShare.Controller.GetHTMLLog (System.IO.Path.GetFileName (LocalPath));
|
||||||
if (HTML == null) { // TODO: there may be a race condition here
|
|
||||||
|
|
||||||
LogContent.Remove (LogContent.Child);
|
|
||||||
Spinner = new SparkleSpinner (22);
|
|
||||||
LogContent.Add (Spinner);
|
|
||||||
LogContent.ShowAll ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread thread = new Thread (new ThreadStart (delegate {
|
|
||||||
|
|
||||||
GenerateHTML ();
|
|
||||||
AddHTML ();
|
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
||||||
thread.Start ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void GenerateHTML () {
|
|
||||||
|
|
||||||
HTML = SparkleShare.Controller.GetHTMLLog (System.IO.Path.GetFileName (LocalPath));
|
|
||||||
|
|
||||||
HTML = HTML.Replace ("<!-- $body-font-size -->", (double) (Style.FontDescription.Size / 1024 + 3) + "px");
|
HTML = HTML.Replace ("<!-- $body-font-size -->", (double) (Style.FontDescription.Size / 1024 + 3) + "px");
|
||||||
HTML = HTML.Replace ("<!-- $day-entry-header-font-size -->", (Style.FontDescription.Size / 1024 + 3) + "px");
|
HTML = HTML.Replace ("<!-- $day-entry-header-font-size -->", (Style.FontDescription.Size / 1024 + 3) + "px");
|
||||||
HTML = HTML.Replace ("<!-- $a-color -->", "#0085cf");
|
HTML = HTML.Replace ("<!-- $a-color -->", "#0085cf");
|
||||||
HTML = HTML.Replace ("<!-- $a-hover-color -->", "#009ff8");
|
HTML = HTML.Replace ("<!-- $a-hover-color -->", "#009ff8");
|
||||||
HTML = HTML.Replace ("<!-- $body-font-family -->", "\"" + Style.FontDescription.Family + "\"");
|
HTML = HTML.Replace ("<!-- $body-font-family -->", "\"" + Style.FontDescription.Family + "\"");
|
||||||
HTML = HTML.Replace ("<!-- $body-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Normal)));
|
HTML = HTML.Replace ("<!-- $body-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Normal)));
|
||||||
HTML = HTML.Replace ("<!-- $body-background-color -->", SparkleUIHelpers.GdkColorToHex (new TreeView ().Style.Base (StateType.Normal)));
|
HTML = HTML.Replace ("<!-- $body-background-color -->", SparkleUIHelpers.GdkColorToHex (new TreeView ().Style.Base (StateType.Normal)));
|
||||||
HTML = HTML.Replace ("<!-- $day-entry-header-background-color -->", SparkleUIHelpers.GdkColorToHex (Style.Background (StateType.Normal)));
|
HTML = HTML.Replace ("<!-- $day-entry-header-background-color -->", SparkleUIHelpers.GdkColorToHex (Style.Background (StateType.Normal)));
|
||||||
HTML = HTML.Replace ("<!-- $secondary-font-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
|
HTML = HTML.Replace ("<!-- $secondary-font-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
|
||||||
HTML = HTML.Replace ("<!-- $small-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
|
HTML = HTML.Replace ("<!-- $small-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
|
||||||
HTML = HTML.Replace ("<!-- $no-buddy-icon-background-image -->", "file://" +
|
HTML = HTML.Replace ("<!-- $no-buddy-icon-background-image -->", "file://" +
|
||||||
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
||||||
"hicolor", "32x32", "status", "avatar-default.png"));
|
"hicolor", "32x32", "status", "avatar-default.png"));
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void AddHTML ()
|
private void AddHTML ()
|
||||||
{
|
{
|
||||||
|
Application.Invoke (delegate {
|
||||||
|
Spinner.Stop ();
|
||||||
|
LogContent.Remove (LogContent.Child);
|
||||||
|
|
||||||
Application.Invoke (delegate {
|
ScrolledWindow = new ScrolledWindow () {
|
||||||
|
HscrollbarPolicy = PolicyType.Never
|
||||||
|
};
|
||||||
|
|
||||||
|
Viewport viewport = new Viewport () {
|
||||||
|
ShadowType = ShadowType.None
|
||||||
|
};
|
||||||
|
|
||||||
Spinner.Stop ();
|
WebView.Reparent (viewport);
|
||||||
LogContent.Remove (LogContent.Child);
|
ScrolledWindow.Add (viewport);
|
||||||
|
|
||||||
ScrolledWindow = new ScrolledWindow () {
|
WebView.LoadString (HTML, null, null, "file://");
|
||||||
HscrollbarPolicy = PolicyType.Never
|
|
||||||
};
|
|
||||||
|
|
||||||
Viewport viewport = new Viewport () {
|
|
||||||
ShadowType = ShadowType.None
|
|
||||||
};
|
|
||||||
|
|
||||||
WebView.Reparent (viewport);
|
LogContent.Add (ScrolledWindow);
|
||||||
ScrolledWindow.Add (viewport);
|
LogContent.ShowAll ();
|
||||||
|
});
|
||||||
WebView.LoadString (HTML, null, null, "file://");
|
}
|
||||||
|
|
||||||
LogContent.Add (ScrolledWindow);
|
|
||||||
LogContent.ShowAll ();
|
|
||||||
|
|
||||||
|
|
||||||
});
|
public void Close (object o, DeleteEventArgs args)
|
||||||
|
{
|
||||||
}
|
HideAll ();
|
||||||
|
args.RetVal = true;
|
||||||
|
// TODO: window positions aren't saved
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Close (object o, DeleteEventArgs args)
|
private MenuBar CreateShortcutsBar ()
|
||||||
{
|
{
|
||||||
|
// Adds a hidden menubar that contains to enable keyboard
|
||||||
|
// shortcuts to close the log
|
||||||
|
MenuBar = new MenuBar ();
|
||||||
|
|
||||||
HideAll ();
|
MenuItem file_item = new MenuItem ("File");
|
||||||
args.RetVal = true;
|
|
||||||
// FIXME: window positions aren't saved
|
|
||||||
|
|
||||||
}
|
Menu file_menu = new Menu ();
|
||||||
|
|
||||||
|
MenuItem close_1 = new MenuItem ("Close1");
|
||||||
|
MenuItem close_2 = new MenuItem ("Close2");
|
||||||
|
|
||||||
|
// adds specific Ctrl+W and Esc key accelerators to Log Window
|
||||||
|
AccelGroup accel_group = new AccelGroup ();
|
||||||
|
AddAccelGroup (accel_group);
|
||||||
|
|
||||||
private MenuBar CreateShortcutsBar () {
|
// Close on Esc
|
||||||
|
close_1.AddAccelerator ("activate", accel_group, new AccelKey (Gdk.Key.W, Gdk.ModifierType.ControlMask,
|
||||||
|
AccelFlags.Visible));
|
||||||
|
|
||||||
// Adds a hidden menubar that contains to enable keyboard
|
close_1.Activated += delegate { HideAll (); };
|
||||||
// shortcuts to close the log
|
|
||||||
MenuBar = new MenuBar ();
|
|
||||||
|
|
||||||
MenuItem file_item = new MenuItem ("File");
|
// Close on Ctrl+W
|
||||||
|
close_2.AddAccelerator ("activate", accel_group, new AccelKey (Gdk.Key.Escape, Gdk.ModifierType.None,
|
||||||
|
AccelFlags.Visible));
|
||||||
|
close_2.Activated += delegate { HideAll (); };
|
||||||
|
|
||||||
Menu file_menu = new Menu ();
|
file_menu.Append (close_1);
|
||||||
|
file_menu.Append (close_2);
|
||||||
|
|
||||||
MenuItem close_1 = new MenuItem ("Close1");
|
file_item.Submenu = file_menu;
|
||||||
MenuItem close_2 = new MenuItem ("Close2");
|
|
||||||
|
|
||||||
// adds specific Ctrl+W and Esc key accelerators to Log Window
|
|
||||||
AccelGroup accel_group = new AccelGroup ();
|
|
||||||
AddAccelGroup (accel_group);
|
|
||||||
|
|
||||||
// Close on Esc
|
MenuBar.Append (file_item);
|
||||||
close_1.AddAccelerator ("activate", accel_group, new AccelKey (Gdk.Key.W, Gdk.ModifierType.ControlMask,
|
|
||||||
AccelFlags.Visible));
|
|
||||||
|
|
||||||
close_1.Activated += delegate { HideAll (); };
|
// Hacky way to hide the menubar, but the accellerators
|
||||||
|
// will simply be disabled when using Hide ()
|
||||||
// Close on Ctrl+W
|
MenuBar.HeightRequest = 1;
|
||||||
close_2.AddAccelerator ("activate", accel_group, new AccelKey (Gdk.Key.Escape, Gdk.ModifierType.None,
|
MenuBar.ModifyBg (StateType.Normal, Style.Background (StateType.Normal));
|
||||||
AccelFlags.Visible));
|
|
||||||
close_2.Activated += delegate { HideAll (); };
|
|
||||||
|
|
||||||
file_menu.Append (close_1);
|
|
||||||
file_menu.Append (close_2);
|
|
||||||
|
|
||||||
file_item.Submenu = file_menu;
|
|
||||||
|
|
||||||
MenuBar.Append (file_item);
|
|
||||||
|
|
||||||
// Hacky way to hide the menubar, but the accellerators
|
|
||||||
// will simply be disabled when using Hide ()
|
|
||||||
MenuBar.HeightRequest = 1;
|
|
||||||
MenuBar.ModifyBg (StateType.Normal, Style.Background (StateType.Normal));
|
|
||||||
|
|
||||||
return MenuBar;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return MenuBar;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue