log: fix coding style and whitespace

This commit is contained in:
Hylke Bons 2011-05-14 01:11:30 +01:00
parent 9901ca56ba
commit a38442caf6

View file

@ -28,268 +28,237 @@ using WebKit;
namespace SparkleShare {
public class SparkleLog : Window {
public class SparkleLog : Window {
public readonly string LocalPath;
public readonly string LocalPath;
private ScrolledWindow ScrolledWindow;
private MenuBar MenuBar;
private WebView WebView;
private string LinkStatus;
private SparkleSpinner Spinner;
private string HTML;
private EventBox LogContent;
private ScrolledWindow ScrolledWindow;
private MenuBar MenuBar;
private WebView WebView;
private string LinkStatus;
private SparkleSpinner Spinner;
private string HTML;
private EventBox LogContent;
// Short alias for the translations
public static string _ (string s)
{
return Catalog.GetString (s);
}
// Short alias for the translations
public static string _ (string s)
{
return Catalog.GetString (s);
}
public SparkleLog (string path) : base ("")
{
LocalPath = path;
string name = System.IO.Path.GetFileName (LocalPath);
SetSizeRequest (480, 640);
public SparkleLog (string path) : base ("")
{
LocalPath = path;
string name = System.IO.Path.GetFileName (LocalPath);
SetSizeRequest (480, 640);
Resizable = false;
BorderWidth = 0;
SetPosition (WindowPosition.Center);
BorderWidth = 0;
SetPosition (WindowPosition.Center);
// Open slightly off center for each consecutive window
if (SparkleUI.OpenLogs.Count > 0) {
// Open slightly off center for each consecutive window
if (SparkleUI.OpenLogs.Count > 0) {
int x, y;
GetPosition (out x, out y);
Move (x + SparkleUI.OpenLogs.Count * 20, y + SparkleUI.OpenLogs.Count * 20);
int x, y;
GetPosition (out x, out y);
Move (x + SparkleUI.OpenLogs.Count * 20, y + SparkleUI.OpenLogs.Count * 20);
}
// TRANSLATORS: {0} is a folder name, and {1} is a server address
Title = String.Format(_("Events in {0}"), name);
IconName = "folder-sparkleshare";
}
// TRANSLATORS: {0} is a folder name, and {1} is a server address
Title = String.Format(_("Events in {0}"), name);
IconName = "folder-sparkleshare";
DeleteEvent += Close;
DeleteEvent += Close;
CreateEventLog ();
UpdateEventLog ();
}
CreateEventLog ();
UpdateEventLog ();
}
private void CreateEventLog () {
private void CreateEventLog ()
{
LogContent = new EventBox ();
VBox layout_vertical = new VBox (false, 0);
LogContent = new EventBox ();
VBox layout_vertical = new VBox (false, 0);
ScrolledWindow = new ScrolledWindow ();
ScrolledWindow = new ScrolledWindow ();
WebView = new WebView () {
Editable = false
};
WebView = new WebView () {
Editable = false
};
WebView.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
LinkStatus = args.Link;
};
WebView.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
LinkStatus = args.Link;
};
WebView.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
if (args.Request.Uri == LinkStatus) {
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
// FIXME: Use the right event, waiting for newer webkit bindings
WebView.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
if (args.Request.Uri == LinkStatus) {
Process process = new Process ();
process.StartInfo.FileName = "xdg-open";
process.StartInfo.Arguments = args.Request.Uri.Replace (" ", "\\ "); // Escape space-characters
process.Start ();
UpdateEventLog ();
}
};
}
ScrolledWindow.AddWithViewport (WebView);
LogContent.Add (ScrolledWindow);
};
layout_vertical.PackStart (LogContent, true, true, 0);
ScrolledWindow.AddWithViewport (WebView);
LogContent.Add (ScrolledWindow);
HButtonBox dialog_buttons = new HButtonBox {
Layout = ButtonBoxStyle.Edge,
BorderWidth = 12
};
layout_vertical.PackStart (LogContent, true, true, 0);
HButtonBox dialog_buttons = new HButtonBox {
Layout = ButtonBoxStyle.Edge,
BorderWidth = 12
};
Button open_folder_button = new Button (_("_Open Folder")) {
UseUnderline = true
};
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 ();
process.StartInfo.FileName = "xdg-open";
process.StartInfo.Arguments = LocalPath.Replace (" ", "\\ "); // Escape space-characters
process.Start ();
Button close_button = new Button (Stock.Close);
};
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 {
HideAll ();
};
// We have to hide the menubar somewhere...
layout_vertical.PackStart (CreateShortcutsBar (), false, false, 0);
layout_vertical.PackStart (dialog_buttons, false, false, 0);
dialog_buttons.Add (open_folder_button);
dialog_buttons.Add (close_button);
Add (layout_vertical);
// We have to hide the menubar somewhere...
layout_vertical.PackStart (CreateShortcutsBar (), false, false, 0);
layout_vertical.PackStart (dialog_buttons, false, false, 0);
Add (layout_vertical);
ShowAll ();
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 ()
{
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));
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 ("<!-- $day-entry-header-font-size -->", (Style.FontDescription.Size / 1024 + 3) + "px");
HTML = HTML.Replace ("<!-- $a-color -->", "#0085cf");
HTML = HTML.Replace ("<!-- $a-hover-color -->", "#009ff8");
HTML = HTML.Replace ("<!-- $body-font-family -->", "\"" + Style.FontDescription.Family + "\"");
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 ("<!-- $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 ("<!-- $small-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
HTML = HTML.Replace ("<!-- $no-buddy-icon-background-image -->", "file://" +
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
"hicolor", "32x32", "status", "avatar-default.png"));
}
HTML = HTML.Replace ("<!-- $body-font-family -->", "\"" + Style.FontDescription.Family + "\"");
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 ("<!-- $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 ("<!-- $small-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
HTML = HTML.Replace ("<!-- $no-buddy-icon-background-image -->", "file://" +
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
"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 ();
LogContent.Remove (LogContent.Child);
WebView.Reparent (viewport);
ScrolledWindow.Add (viewport);
ScrolledWindow = new ScrolledWindow () {
HscrollbarPolicy = PolicyType.Never
};
Viewport viewport = new Viewport () {
ShadowType = ShadowType.None
};
WebView.LoadString (HTML, null, null, "file://");
WebView.Reparent (viewport);
ScrolledWindow.Add (viewport);
WebView.LoadString (HTML, null, null, "file://");
LogContent.Add (ScrolledWindow);
LogContent.ShowAll ();
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 ();
args.RetVal = true;
// FIXME: window positions aren't saved
MenuItem file_item = new MenuItem ("File");
}
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
// shortcuts to close the log
MenuBar = new MenuBar ();
close_1.Activated += delegate { HideAll (); };
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");
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);
file_item.Submenu = file_menu;
// Close on Esc
close_1.AddAccelerator ("activate", accel_group, new AccelKey (Gdk.Key.W, Gdk.ModifierType.ControlMask,
AccelFlags.Visible));
MenuBar.Append (file_item);
close_1.Activated += delegate { HideAll (); };
// 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 (); };
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;
}
}
// 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;
}
}
}