[log][link] cleanup code
This commit is contained in:
parent
f655649840
commit
d2fd8e8a98
|
@ -19,29 +19,31 @@ using System.IO;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleLink : EventBox {
|
|
||||||
|
|
||||||
private Label Label;
|
// A clickable link that corresponds to a local file
|
||||||
|
public class SparkleLink : EventBox {
|
||||||
|
|
||||||
public SparkleLink (string title, string url) : base ()
|
public SparkleLink (string title, string url) : base ()
|
||||||
{
|
{
|
||||||
|
|
||||||
Label = new Label (title) {
|
Label label = new Label (title) {
|
||||||
Ellipsize = Pango.EllipsizeMode.Middle,
|
Ellipsize = Pango.EllipsizeMode.Middle,
|
||||||
UseMarkup = true,
|
UseMarkup = true,
|
||||||
Xalign = 0
|
Xalign = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
Add (Label);
|
Add (label);
|
||||||
|
|
||||||
|
// Only make links for files that exist
|
||||||
if (!File.Exists (url))
|
if (!File.Exists (url))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Use Tango blue for the links
|
||||||
Gdk.Color color = new Gdk.Color ();
|
Gdk.Color color = new Gdk.Color ();
|
||||||
Gdk.Color.Parse ("#3465a4", ref color);
|
Gdk.Color.Parse ("#3465a4", ref color);
|
||||||
Label.ModifyFg (StateType.Normal, color);
|
label.ModifyFg (StateType.Normal, color);
|
||||||
|
|
||||||
|
// Open the URL when it is clicked
|
||||||
ButtonPressEvent += delegate {
|
ButtonPressEvent += delegate {
|
||||||
|
|
||||||
Process process = new Process ();
|
Process process = new Process ();
|
||||||
|
@ -51,16 +53,18 @@ namespace SparkleShare {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add underline when hovering the link with the cursor
|
||||||
EnterNotifyEvent += delegate {
|
EnterNotifyEvent += delegate {
|
||||||
|
|
||||||
Label.Markup = "<u>" + title + "</u>";
|
label.Markup = "<u>" + title + "</u>";
|
||||||
ShowAll ();
|
ShowAll ();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Remove underline when leaving the link with the cursor
|
||||||
LeaveNotifyEvent += delegate {
|
LeaveNotifyEvent += delegate {
|
||||||
|
|
||||||
Label.Markup = title;
|
label.Markup = title;
|
||||||
ShowAll ();
|
ShowAll ();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -208,21 +208,13 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VBox layout_vertical = new VBox (false, 0);
|
VBox layout_vertical = new VBox (false, 0);
|
||||||
|
|
||||||
|
TreeView tree_view = new TreeView ();
|
||||||
|
Gdk.Color background_color = tree_view.Style.Base (StateType.Normal);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TreeView tree_view = new TreeView ();
|
|
||||||
foreach (ActivityDay activity_day in activity_days) {
|
foreach (ActivityDay activity_day in activity_days) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Label date_label = new Label ("") {
|
Label date_label = new Label ("") {
|
||||||
UseMarkup = true,
|
UseMarkup = true,
|
||||||
Xpad = 9,
|
Xpad = 9,
|
||||||
|
@ -252,71 +244,122 @@ namespace SparkleShare {
|
||||||
|
|
||||||
layout_vertical.PackStart (date_label, true, true, 0);
|
layout_vertical.PackStart (date_label, true, true, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Gdk.Color color = Style.Foreground (StateType.Insensitive);
|
Gdk.Color color = Style.Foreground (StateType.Insensitive);
|
||||||
string secondary_text_color = GdkColorToHex (color);
|
string secondary_text_color = GdkColorToHex (color);
|
||||||
|
|
||||||
foreach (ChangeSet change_set in activity_day) {
|
foreach (ChangeSet change_set in activity_day) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VBox log_entry = new VBox (false, 0);
|
VBox log_entry = new VBox (false, 0);
|
||||||
VBox deleted_files = new VBox (false, 0);
|
VBox deleted_files = new VBox (false, 0);
|
||||||
VBox edited_files = new VBox (false, 0);
|
VBox edited_files = new VBox (false, 0);
|
||||||
VBox added_files = new VBox (false, 0);
|
VBox added_files = new VBox (false, 0);
|
||||||
|
|
||||||
|
foreach (string file_path in change_set.Edited) {
|
||||||
|
|
||||||
|
SparkleLink link = new SparkleLink (file_path,
|
||||||
|
SparkleHelpers.CombineMore (LocalPath, file_path));
|
||||||
|
|
||||||
|
link.ModifyBg (StateType.Normal, background_color);
|
||||||
|
|
||||||
|
link.ButtonPressEvent += delegate {
|
||||||
|
Destroy ();
|
||||||
|
};
|
||||||
|
|
||||||
foreach (string file_path in change_set.Edited){
|
|
||||||
SparkleLink link = new SparkleLink (file_path, SparkleHelpers.CombineMore (LocalPath, file_path));
|
|
||||||
edited_files.PackStart (link, false, false, 0);
|
edited_files.PackStart (link, false, false, 0);
|
||||||
|
|
||||||
link.ModifyBg (StateType.Normal, tree_view.Style.Base (StateType.Normal));
|
|
||||||
|
|
||||||
}
|
|
||||||
// TODO: add close delegate
|
|
||||||
foreach (string file_path in change_set.Added)
|
|
||||||
added_files.PackStart (new SparkleLink (file_path, SparkleHelpers.CombineMore (LocalPath, file_path)), false, false, 0);
|
|
||||||
|
|
||||||
foreach (string file_path in change_set.Deleted)
|
}
|
||||||
deleted_files.PackStart (new SparkleLink (file_path, SparkleHelpers.CombineMore (LocalPath, file_path)), false, false, 0);
|
|
||||||
|
|
||||||
|
|
||||||
log_entry.PackStart(new Label ("<b>" + change_set.UserName + "</b>\n" +
|
foreach (string file_path in change_set.Added) {
|
||||||
"<span fgcolor='" + secondary_text_color +"'><small>" +
|
|
||||||
"at " + change_set.DateTime.ToString ("HH:mm") +
|
SparkleLink link = new SparkleLink (file_path,
|
||||||
"</small></span>") { UseMarkup = true, Xalign = 0});
|
SparkleHelpers.CombineMore (LocalPath, file_path));
|
||||||
|
|
||||||
|
link.ModifyBg (StateType.Normal, background_color);
|
||||||
|
|
||||||
|
link.ButtonPressEvent += delegate {
|
||||||
|
Destroy ();
|
||||||
|
};
|
||||||
|
|
||||||
|
added_files.PackStart (link, false, false, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
foreach (string file_path in change_set.Deleted) {
|
||||||
|
|
||||||
|
SparkleLink link = new SparkleLink (file_path,
|
||||||
|
SparkleHelpers.CombineMore (LocalPath, file_path));
|
||||||
|
|
||||||
|
link.ModifyBg (StateType.Normal, background_color);
|
||||||
|
|
||||||
|
link.ButtonPressEvent += delegate {
|
||||||
|
Destroy ();
|
||||||
|
};
|
||||||
|
|
||||||
|
deleted_files.PackStart (link, false, false, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
log_entry.PackStart (new Label ("<b>" + change_set.UserName + "</b>\n" +
|
||||||
|
"<span fgcolor='" + secondary_text_color +"'><small>" +
|
||||||
|
"at " + change_set.DateTime.ToString ("HH:mm") +
|
||||||
|
"</small></span>") { UseMarkup = true, Xalign = 0 });
|
||||||
|
|
||||||
if (edited_files.Children.Length > 0) {
|
if (edited_files.Children.Length > 0) {
|
||||||
|
|
||||||
log_entry.PackStart (new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>Edited</small></span>") { UseMarkup=true, Xalign = 0}, false, false, 0);
|
Label edited_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
|
||||||
|
"Edited" +
|
||||||
|
"</small></span>") {
|
||||||
|
UseMarkup=true,
|
||||||
|
Xalign = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
log_entry.PackStart (edited_label, false, false, 0);
|
||||||
log_entry.PackStart (edited_files, false, false, 0);
|
log_entry.PackStart (edited_files, false, false, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (added_files.Children.Length > 0) {
|
if (added_files.Children.Length > 0) {
|
||||||
|
|
||||||
log_entry.PackStart (new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>Added</small></span>") { UseMarkup=true, Xalign = 0}, false, false, 0);
|
Label added_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
|
||||||
|
"Added" +
|
||||||
|
"</small></span>") {
|
||||||
|
UseMarkup=true,
|
||||||
|
Xalign = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
log_entry.PackStart (added_label, false, false, 0);
|
||||||
log_entry.PackStart (added_files, false, false, 0);
|
log_entry.PackStart (added_files, false, false, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleted_files.Children.Length > 0) {
|
if (deleted_files.Children.Length > 0) {
|
||||||
|
|
||||||
log_entry.PackStart (new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>Deleted</small></span>") { UseMarkup=true, Xalign = 0}, false, false, 0);
|
Label deleted_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
|
||||||
log_entry.PackStart (deleted_files, false, false, 0);
|
"Edited" +
|
||||||
}
|
"</small></span>") {
|
||||||
|
UseMarkup=true,
|
||||||
|
Xalign = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
log_entry.PackStart (deleted_label, false, false, 0);
|
||||||
|
log_entry.PackStart (deleted_files, false, false, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
HBox hbox = new HBox (false, 0);
|
HBox hbox = new HBox (false, 0);
|
||||||
|
|
||||||
Image i = new Image (SparkleHelpers.GetAvatar (change_set.UserEmail, 32)) {
|
Image avatar = new Image (SparkleHelpers.GetAvatar (change_set.UserEmail, 32)) {
|
||||||
Yalign = 0
|
Yalign = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
hbox.PackStart (i, false, false, 18);
|
hbox.PackStart (avatar, false, false, 18);
|
||||||
VBox vbox = new VBox (false, 0);
|
|
||||||
|
VBox vbox = new VBox (false, 0);
|
||||||
|
vbox.PackStart (log_entry, true, true, 0);
|
||||||
|
|
||||||
vbox.PackStart (log_entry, true, true, 0);
|
|
||||||
hbox.PackStart (vbox, true, true, 0);
|
hbox.PackStart (vbox, true, true, 0);
|
||||||
hbox.PackStart (new Label (""), false, false, 12);
|
hbox.PackStart (new Label (""), false, false, 12);
|
||||||
|
|
||||||
|
@ -324,19 +367,15 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// layout_vertical.PackStart (icon_view, false, false, 0);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrolledWindow = new ScrolledWindow ();
|
ScrolledWindow = new ScrolledWindow ();
|
||||||
ScrolledWindow.ShadowType = ShadowType.None;
|
ScrolledWindow.ShadowType = ShadowType.None;
|
||||||
EventBox wrapper = new EventBox ();
|
|
||||||
wrapper.ModifyBg (StateType.Normal, tree_view.Style.Base (StateType.Normal));
|
EventBox wrapper = new EventBox ();
|
||||||
wrapper.Add (layout_vertical);
|
wrapper.ModifyBg (StateType.Normal, background_color);
|
||||||
|
wrapper.Add (layout_vertical);
|
||||||
|
|
||||||
ScrolledWindow.AddWithViewport (wrapper);
|
ScrolledWindow.AddWithViewport (wrapper);
|
||||||
|
|
||||||
return ScrolledWindow;
|
return ScrolledWindow;
|
||||||
|
|
Loading…
Reference in a new issue