From d1dddc096b19152e20a0283062462eceb28665ad Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 22 Jun 2010 00:46:36 +0100 Subject: [PATCH 01/16] Start of the Nautilus extension --- .../sparkleshare-nautilus-extension.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 SparkleShare/Nautilus/sparkleshare-nautilus-extension.py diff --git a/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py b/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py new file mode 100644 index 00000000..c37d8bea --- /dev/null +++ b/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py @@ -0,0 +1,63 @@ +# SparkleShare, an instant update workflow to Git. +# Copyright (C) 2010 Hylke Bons +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +import gio +import nautilus +import os + +SPARKLESHARE_DIR = os.path.expanduser ('~') + '/SparkleShare' + +class SparkleShareExtension (nautilus.MenuProvider): + + def __init__ (self): + + name = 'Loaded Nautilus SparkleShareExtension.' + + + def get_file_items (self, window, files): + + # Only work when one file is selected + if len (files) != 1: + return + + # Get info about the selected file + file_reference = gio.File (files [0].get_uri ()) + + # Only work if in a SparkleShare repo + if file_reference.get_path () [:len(SPARKLESHARE_DIR)] != SPARKLESHARE_DIR: + return + + submenu = nautilus.Menu () + + # Create the submenu for the nautilus context menu + item = nautilus.MenuItem ('Nautilus::OpenOlderVersion', 'Open Older Version', + 'Make a copy of an older version of this document in SparkleShare') + item.set_submenu (submenu) + + os.chdir (file_reference.get_parent ().get_path ()) + command = os.popen ("git log --pretty=oneline") + + for line in command.readlines (): + submenu.append_item (nautilus.MenuItem ('Nautilus::Version', line, + 'Select to open a copy of this version')) + + item_open_log = nautilus.MenuItem ('Nautilus::OpenEventLog', 'Open Event Log' + file_reference.get_path (), + 'Open the event log for this document to see more versions') + + submenu.append_item(item_open_log) + + return item, From 7072206bb6fffca0834de7565e746c7c78635a02 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 25 Jun 2010 01:54:30 +0100 Subject: [PATCH 02/16] continuation of nautilus extension, though a bit broken --- .../sparkleshare-nautilus-extension.py | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py b/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py index c37d8bea..84e2b5c9 100644 --- a/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py +++ b/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . - +import time import gio import nautilus import os @@ -25,38 +25,50 @@ class SparkleShareExtension (nautilus.MenuProvider): def __init__ (self): - name = 'Loaded Nautilus SparkleShareExtension.' + name = "Loaded Nautilus SparkleShareExtension." + def checkout_file (commit) + return def get_file_items (self, window, files): - # Only work when one file is selected + # Only work when one file is selected if len (files) != 1: return - # Get info about the selected file file_reference = gio.File (files [0].get_uri ()) - # Only work if in a SparkleShare repo - if file_reference.get_path () [:len(SPARKLESHARE_DIR)] != SPARKLESHARE_DIR: + # Only work if we're in a SparkleShare repo + if file_reference.get_path () [:len (SPARKLESHARE_DIR)] != SPARKLESHARE_DIR: return - submenu = nautilus.Menu () + item = nautilus.MenuItem ("Nautilus::OpenOlderVersion", "Get Earlier Version", + "Make a copy of an earlier version in this folder") - # Create the submenu for the nautilus context menu - item = nautilus.MenuItem ('Nautilus::OpenOlderVersion', 'Open Older Version', - 'Make a copy of an older version of this document in SparkleShare') + submenu = nautilus.Menu () item.set_submenu (submenu) + timestamps = array ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + os.chdir (file_reference.get_parent ().get_path ()) - command = os.popen ("git log --pretty=oneline") + time_command = os.popen ("git log -10 --format='%at' " + file_reference.get_path ()) + author_command = os.popen ("git log -10 --format='%an' " + file_reference.get_path ()) - for line in command.readlines (): - submenu.append_item (nautilus.MenuItem ('Nautilus::Version', line, - 'Select to open a copy of this version')) + i = 0 + for line in time_command.readlines (): + timestamps [i] = line + i += 1 - item_open_log = nautilus.MenuItem ('Nautilus::OpenEventLog', 'Open Event Log' + file_reference.get_path (), - 'Open the event log for this document to see more versions') + i = 0 + for line in author_command.readlines (): + timestamp = time.strftime ("%a, %d %b %Y %H:%M", time.localtime (timestamps [i])) + submenu.append_item (nautilus.MenuItem ("Nautilus::Version" + timestamps [i], timestamp + + " " + line.strip ("\n"), + "Select to get a copy of this version")) + i += 1 + + item_open_log = nautilus.MenuItem ("Nautilus::s", "Open Event Log" + file_reference.get_path (), + "Open the event log to see more versions") submenu.append_item(item_open_log) From 66ae6fada1954fae9a77fe15fa4a91a07b4a2441 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 26 Jun 2010 20:19:33 +0100 Subject: [PATCH 03/16] make nautilus extension work and make the date formats consistent with those of conflicting files --- .../sparkleshare-nautilus-extension.py | 111 +++++++++++++----- SparkleShare/SparkleRepo.cs | 4 +- 2 files changed, 86 insertions(+), 29 deletions(-) diff --git a/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py b/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py index 84e2b5c9..56885fb1 100644 --- a/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py +++ b/SparkleShare/Nautilus/sparkleshare-nautilus-extension.py @@ -12,64 +12,121 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . +import os +import shutil import time + import gio import nautilus -import os -SPARKLESHARE_DIR = os.path.expanduser ('~') + '/SparkleShare' +SPARKLESHARE_PATH = os.path.join (os.path.expanduser ('~'), "SparkleShare") class SparkleShareExtension (nautilus.MenuProvider): + def __init__ (self): - name = "Loaded Nautilus SparkleShareExtension." + debug = "Loaded Nautilus SparkleShare Extension." - def checkout_file (commit) + + def checkout_version (self, menu, file_reference, commit_hash, username, timestamp): + + file_name = file_reference.get_basename ().replace (" ", "\ ").replace ("(", "\(").replace (")", "\)") + file_path = file_reference.get_path ().replace (" ", "\ ").replace ("(", "\(").replace (")", "\)") + tmp_file_path = os.path.join (SPARKLESHARE_PATH, ".tmp", file_reference.get_basename ()) + + # Move the current version to a temporary path + shutil.move (file_reference.get_path (), tmp_file_path) + + # Check out the earlier version + os.chdir (file_reference.get_parent ().get_path ()) + os.popen ("git checkout " + commit_hash + " " + file_name + .replace (" ", "\ ").replace ("(", "\(").replace (")", "\)")) + + new_tmp_file_name = file_name + " (" + username + ", " + new_tmp_file_name += time.strftime ("%H:%M %d %b %Y", timestamp).replace (" 0", " ") + ") " + + # Rename the checked out file + shutil.move (file_name, new_tmp_file_name) + + # Move the original file back + shutil.move (tmp_file_path, file_path) + + return True + + + def compare_versions (self, menu, file_reference): return + def get_file_items (self, window, files): - # Only work when one file is selected + # Only work if one file is selected if len (files) != 1: return file_reference = gio.File (files [0].get_uri ()) - # Only work if we're in a SparkleShare repo - if file_reference.get_path () [:len (SPARKLESHARE_DIR)] != SPARKLESHARE_DIR: + # Only work if we're in a SparkleShare repository folder + if not (file_reference.get_path ().startswith (SPARKLESHARE_PATH)): return - item = nautilus.MenuItem ("Nautilus::OpenOlderVersion", "Get Earlier Version", - "Make a copy of an earlier version in this folder") - - submenu = nautilus.Menu () - item.set_submenu (submenu) - - timestamps = array ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + epochs = ["", "", "", "", "", "", "", "", "", ""] + commit_hashes = ["", "", "", "", "", "", "", "", "", ""] os.chdir (file_reference.get_parent ().get_path ()) - time_command = os.popen ("git log -10 --format='%at' " + file_reference.get_path ()) - author_command = os.popen ("git log -10 --format='%an' " + file_reference.get_path ()) + + time_command = os.popen ("git log -10 --format='%at' " + file_reference.get_path () + .replace (" ", "\ ").replace ("(", "\(").replace (")", "\)")) + + author_command = os.popen ("git log -10 --format='%an' " + file_reference.get_path () + .replace (" ", "\ ").replace ("(", "\(").replace (")", "\)")) + + hash_command = os.popen ("git log -10 --format='%H' " + file_reference.get_path () + .replace (" ", "\ ").replace ("(", "\(").replace (")", "\)")) i = 0 for line in time_command.readlines (): - timestamps [i] = line + epochs [i] = line.strip ("\n") i += 1 + if i < 2: + return + + i = 0 + for line in hash_command.readlines (): + commit_hashes [i] = line.strip ("\n") + i += 1 + + earlier_version_menu_item = nautilus.MenuItem ("Nautilus::OpenOlderVersion", "Get Earlier Version", + "Make a copy of an earlier version in this folder") + submenu = nautilus.Menu () + i = 0 for line in author_command.readlines (): - timestamp = time.strftime ("%a, %d %b %Y %H:%M", time.localtime (timestamps [i])) - submenu.append_item (nautilus.MenuItem ("Nautilus::Version" + timestamps [i], timestamp + - " " + line.strip ("\n"), - "Select to get a copy of this version")) + + if i > 0: + + timestamp = time.strftime ("%d %b\t%H:%M", time.localtime (float (epochs [i]))) + username = line.strip ("\n") + + menu_item = nautilus.MenuItem ("Nautilus::Version" + epochs [i], + timestamp + "\t" + username, + "Select to get a copy of this version") + + menu_item.connect ("activate", self.checkout_version, file_reference, commit_hashes [i], + username, time.localtime (float (epochs [i]))) + submenu.append_item (menu_item) + i += 1 - item_open_log = nautilus.MenuItem ("Nautilus::s", "Open Event Log" + file_reference.get_path (), - "Open the event log to see more versions") - - submenu.append_item(item_open_log) + earlier_version_menu_item.set_submenu (submenu) - return item, +# compare_versions_menu_item = nautilus.MenuItem ("Nautilus::CompareVersions", "Compare Versions", +# "Compare two versions of this document at any point in time") + +# compare_versions_menu_item = menu_item.connect ("activate", self.compare_versions, file_reference) + + return earlier_version_menu_item, diff --git a/SparkleShare/SparkleRepo.cs b/SparkleShare/SparkleRepo.cs index d9dac422..8d856d6a 100644 --- a/SparkleShare/SparkleRepo.cs +++ b/SparkleShare/SparkleRepo.cs @@ -257,10 +257,10 @@ namespace SparkleShare { Process.Start (); DateTime DateTime = new DateTime (); - string TimeStamp = DateTime.Now.ToString ("H:mm, d MMM yyyy"); + string TimeStamp = DateTime.Now.ToString ("H:mm d MMM yyyy"); File.Move (ProblemFileName, - ProblemFileName + " (" + UserName + " - " + TimeStamp + ")"); + ProblemFileName + " (" + UserName + ", " + TimeStamp + ")"); Process.StartInfo.Arguments = "checkout --theirs " + ProblemFileName; From e91c4e73eaa0be59ed479ada42afcc2ca4a26650 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 26 Jun 2010 21:27:01 +0100 Subject: [PATCH 04/16] update run dependancies --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index bf55a99f..594fb141 100644 --- a/README +++ b/README @@ -37,6 +37,7 @@ SparkleShare currently requires: - notify-sharp >= 0.4.0 - openssh - gvfs >= 1.3 + - nautilus-python Run the service: From 4f8f64e5faa7fd2276b6b1378859740582e4dad7 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sun, 27 Jun 2010 16:59:16 +0200 Subject: [PATCH 05/16] [build] Add the nautilus extension to the build If nautilus-python is present, the extension will be installed in the proper directory. --- SparkleShare/Makefile.am | 27 ++++++++++++++++++++++++ SparkleShare/Nautilus/Makefile.am | 10 +++++++++ build/m4/sparkleshare/nautilus-python.m4 | 14 ++++++++++++ configure.ac | 4 ++++ 4 files changed, 55 insertions(+) create mode 100644 SparkleShare/Makefile.am create mode 100644 SparkleShare/Nautilus/Makefile.am create mode 100644 build/m4/sparkleshare/nautilus-python.m4 diff --git a/SparkleShare/Makefile.am b/SparkleShare/Makefile.am new file mode 100644 index 00000000..29ea226f --- /dev/null +++ b/SparkleShare/Makefile.am @@ -0,0 +1,27 @@ +SUBDIRS = \ + Nautilus + +ASSEMBLY = SparkleShare +TARGET = exe + +LINK = $(REF_SPARKLESHARE) + + +SOURCES = \ +Defines.cs \ +SparkleBubble.cs \ +SparkleDialog.cs \ +SparkleHelpers.cs \ +SparklePaths.cs \ +SparklePlatform.cs \ +SparkleRepo.cs \ +SparkleShare.cs \ +SparkleSpinner.cs \ +SparkleStatusIcon.cs \ +SparkleUI.cs \ +SparkleWindow.cs + +include $(top_srcdir)/build/build.mk + +bin_SCRIPTS = sparkleshare + diff --git a/SparkleShare/Nautilus/Makefile.am b/SparkleShare/Nautilus/Makefile.am new file mode 100644 index 00000000..a821d5e6 --- /dev/null +++ b/SparkleShare/Nautilus/Makefile.am @@ -0,0 +1,10 @@ +SOURCES = \ + sparkleshare-nautilus-extension.py + +if NAUTILUS_EXTENSION_ENABLED +NAUTILUS_PYTHON_INSTALL_DIR=$(subst $(NAUTILUS_LIBDIR),${libdir},$(NAUTILUS_PYTHON_DIR)) +extensiondir = $(NAUTILUS_PYTHON_INSTALL_DIR) +extension_SCRIPTS = $(addprefix $(srcdir)/, $(SOURCES)) +else +EXTRA_DIST = $(SOURCES) +endif diff --git a/build/m4/sparkleshare/nautilus-python.m4 b/build/m4/sparkleshare/nautilus-python.m4 new file mode 100644 index 00000000..d7765330 --- /dev/null +++ b/build/m4/sparkleshare/nautilus-python.m4 @@ -0,0 +1,14 @@ +AC_DEFUN([SPARKLESHARE_NAUTILUS_PYTHON], +[ + PKG_CHECK_MODULES(NAUTILUS_PYTHON, nautilus-python, have_nautilus_python=yes, have_nautilus_python=no) + if test "x$have_nautilus_python" = "xyes"; then + NAUTILUS_LIBDIR="`$PKG_CONFIG --variable=libdir nautilus-python`" + AC_SUBST(NAUTILUS_LIBDIR) + NAUTILUS_PYTHON_DIR="`$PKG_CONFIG --variable=pythondir nautilus-python`" + AC_SUBST(NAUTILUS_PYTHON_DIR) + AM_CONDITIONAL(NAUTILUS_EXTENSION_ENABLED, true) + else + AM_CONDITIONAL(NAUTILUS_EXTENSION_ENABLED, false) + fi +]) + diff --git a/configure.ac b/configure.ac index d3333527..0e8f8f31 100644 --- a/configure.ac +++ b/configure.ac @@ -75,6 +75,9 @@ SHAMROCK_CHECK_MONO_2_0_GAC_ASSEMBLIES([ Mono.Posix ]) +dnl Get nautilus extensions directory +SPARKLESHARE_NAUTILUS_PYTHON + SHAVE_INIT([build/m4/shave], [enable]) @@ -90,6 +93,7 @@ SparkleShare/sparkleshare SparkleShare/Defines.cs SparkleShare/AssemblyInfo.cs SparkleShare/Makefile +SparkleShare/Nautilus/Makefile po/Makefile.in Makefile ]) From f93b0f05f871d1b9e3e6820f19dc035ecb0927f6 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sun, 27 Jun 2010 16:59:40 +0200 Subject: [PATCH 06/16] [build] Fix path to icon-theme-installer script --- data/icons/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am index 5ff9f918..49ba7a25 100644 --- a/data/icons/Makefile.am +++ b/data/icons/Makefile.am @@ -43,7 +43,7 @@ theme_icons = \ status,folder-syncing-22.png \ status,folder-syncing-24.png -install_icon_exec = $(top_srcdir)/icon-theme-installer \ +install_icon_exec = $(top_srcdir)/build/icon-theme-installer \ -t "$(theme)" \ -s "$(srcdir)" \ -d "x$(DESTDIR)" \ From c3923480151717f7cae98a8f7eda331b754722cb Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sun, 27 Jun 2010 17:02:20 +0200 Subject: [PATCH 07/16] [build] Remove useless mono-addins stuff --- build/build.environment.mk | 1 - build/m4/sparkleshare/mono-addins.m4 | 12 ------------ 2 files changed, 13 deletions(-) delete mode 100644 build/m4/sparkleshare/mono-addins.m4 diff --git a/build/build.environment.mk b/build/build.environment.mk index 02a2fe02..0c8fe3d8 100644 --- a/build/build.environment.mk +++ b/build/build.environment.mk @@ -1,6 +1,5 @@ # Initializers MONO_BASE_PATH = -MONO_ADDINS_PATH = # Install Paths DEFAULT_INSTALL_DIR = $(pkglibdir) diff --git a/build/m4/sparkleshare/mono-addins.m4 b/build/m4/sparkleshare/mono-addins.m4 deleted file mode 100644 index 32a48c74..00000000 --- a/build/m4/sparkleshare/mono-addins.m4 +++ /dev/null @@ -1,12 +0,0 @@ -AC_DEFUN([FSPOT_CHECK_MONO_ADDINS], -[ - PKG_CHECK_MODULES(MONO_ADDINS, mono-addins >= 0.3.1) - AC_SUBST(MONO_ADDINS_LIBS) - - PKG_CHECK_MODULES(MONO_ADDINS_SETUP, mono-addins-setup >= 0.3.1) - AC_SUBST(MONO_ADDINS_SETUP_LIBS) - - PKG_CHECK_MODULES(MONO_ADDINS_GUI, mono-addins-gui >= 0.3.1) - AC_SUBST(MONO_ADDINS_GUI_LIBS) -]) - From fbc42ec2a6294ebe29dc9c3bad6781df558b7dc6 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Mon, 28 Jun 2010 13:17:48 +0100 Subject: [PATCH 08/16] SparkleDiff --- SparkleShare/SparkleDiff.cs | 371 ++++++++++++++++++++++++++++++++++++ 1 file changed, 371 insertions(+) create mode 100644 SparkleShare/SparkleDiff.cs diff --git a/SparkleShare/SparkleDiff.cs b/SparkleShare/SparkleDiff.cs new file mode 100644 index 00000000..3372d72d --- /dev/null +++ b/SparkleShare/SparkleDiff.cs @@ -0,0 +1,371 @@ +// SparkleShare, an instant update workflow to Git. +// Copyright (C) 2010 Hylke Bons +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using Gtk; +using Mono.Unix; +using System; +using System.Diagnostics; +using System.IO; +using System.Text.RegularExpressions; + +namespace SparkleShare { + + + public class SparkleDiff + { + + public static void Main (string [] args) + { + + Gtk.Application.Init (); + SparkleDiffWindow sparkle_diff_window; + sparkle_diff_window = new SparkleDiffWindow ("/home/hbons/SparkleShare/Deal/ANDRESDIAZGeorgeWashington.jpg"); + sparkle_diff_window.ShowAll (); + + // The main loop + Gtk.Application.Run (); + + } + + } + + + public class SparkleDiffWindow : Window + { + + // Short alias for the translations + public static string _ (string s) + { + return Catalog.GetString (s); + } + + private string FilePath; + private string FileName; + + private VBox ViewLeft; + private VBox ViewRight; + + private string [] RevisionHashes; + + public SparkleDiffWindow (string file_path) : base ("") + { + + FilePath = file_path; + FileName = System.IO.Path.GetFileName (FilePath); + + SetSizeRequest (1024, 600); + SetPosition (WindowPosition.Center); + + BorderWidth = 12; + + Title = String.Format(_("Comparing Versions of ‘{0}’"), System.IO.Path.GetFileName (FilePath)); + IconName = "folder-sparkleshare"; + + GetRevisions (); + + VBox layout_vertical = new VBox (false, 12); + + HBox layout_horizontal = new HBox (false, 12); + + ViewLeft = CreateRevisionView ("Left"); + ViewRight = CreateRevisionView ("Right"); + layout_horizontal.PackStart (ViewLeft); + layout_horizontal.PackStart (ViewRight); + + HButtonBox dialog_buttons = new HButtonBox (); + dialog_buttons.Layout = ButtonBoxStyle.End; + dialog_buttons.BorderWidth = 0; + + Button CloseButton = new Button (Stock.Close); + CloseButton.Clicked += delegate (object o, EventArgs args) { + Environment.Exit (0); + }; + + dialog_buttons.Add (CloseButton); + + layout_vertical.PackStart (layout_horizontal, true, true, 0); + layout_vertical.PackStart (dialog_buttons, false, false, 0); + + Add (layout_vertical); + + } + + + private string [] GetRevisions () + { + + Process process = new Process (); + process.EnableRaisingEvents = true; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + + process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (FilePath); + process.StartInfo.FileName = "git"; + process.StartInfo.Arguments = "log --format=\"%H\" " + FileName; + process.Start (); + + string output = process.StandardOutput.ReadToEnd ().Trim (); + RevisionHashes = Regex.Split (output, "\n"); + + return RevisionHashes; + + } + + + private void SyncViewsHorizontally (object o, EventArgs args) { + + Widget [] view_left_children = ViewLeft.Children; + ScrolledWindow left_scrolled_window = (ScrolledWindow) view_left_children [0]; + + Widget [] view_right_children = ViewRight.Children; + ScrolledWindow right_scrolled_window = (ScrolledWindow) view_right_children [0]; + + Adjustment source_adjustment = (Adjustment) o; + + if (source_adjustment == left_scrolled_window.Hadjustment) + right_scrolled_window.Hadjustment = source_adjustment; + else + left_scrolled_window.Hadjustment = source_adjustment; + + } + + + private void SyncViewsVertically (object o, EventArgs args) { + + Widget [] view_left_children = ViewLeft.Children; + ScrolledWindow left_scrolled_window = (ScrolledWindow) view_left_children [0]; + + Widget [] view_right_children = ViewRight.Children; + ScrolledWindow right_scrolled_window = (ScrolledWindow) view_right_children [0]; + + Adjustment source_adjustment = (Adjustment) o; + + if (source_adjustment == left_scrolled_window.Vadjustment) + right_scrolled_window.Vadjustment = source_adjustment; + else + left_scrolled_window.Vadjustment = source_adjustment; + + } + + + + private void UpdateViews (object o, EventArgs args) + { + + HBox hbox_left = (HBox) ViewLeft.Children [1]; + ComboBox combobox_left = (ComboBox) hbox_left.Children [1]; + string version_left = RevisionHashes [combobox_left.Active]; + + HBox hbox_right = (HBox) ViewRight.Children [1]; + ComboBox combobox_right = (ComboBox) hbox_right.Children [1]; + string version_right = RevisionHashes [combobox_right.Active]; + + Process process = new Process (); + process.EnableRaisingEvents = true; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + + process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (FilePath); + process.StartInfo.FileName = "git"; + process.StartInfo.Arguments = "show " + version_left + ":" + FileName; + process.Start (); + + Gdk.Pixbuf pixbuf; + pixbuf = new Gdk.Pixbuf ( (System.IO.Stream) process.StandardOutput.BaseStream); + + ViewLeft.Remove (ViewLeft.Children [0]); + ScrolledWindow scrolled_window = new ScrolledWindow (); + scrolled_window.AddWithViewport (new Image (pixbuf)); + + ViewLeft.PackStart (scrolled_window, true, true, 0); + ViewLeft.ReorderChild (scrolled_window, 0); + + scrolled_window.Hadjustment.ValueChanged += SyncViewsHorizontally; + scrolled_window.Vadjustment.ValueChanged += SyncViewsVertically; + + ShowAll (); + + } + + + private VBox CreateRevisionView (string position) + { + + VBox layout_vertical = new VBox (false, 6); + + ScrolledWindow scrolled_window = new ScrolledWindow (); + + Process process = new Process (); + process.EnableRaisingEvents = true; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + + process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (FilePath); + process.StartInfo.FileName = "git"; + process.StartInfo.Arguments = "show HEAD:" + FileName; + process.Start (); + + Gdk.Pixbuf pixbuf; + pixbuf = new Gdk.Pixbuf ( (System.IO.Stream) process.StandardOutput.BaseStream); + + scrolled_window.AddWithViewport (new Image (pixbuf)); + + scrolled_window.Hadjustment.ValueChanged += SyncViewsHorizontally; + scrolled_window.Vadjustment.ValueChanged += SyncViewsVertically; + + HBox controls = new HBox (false, 6); + + ComboBox revision_combobox = ComboBox.NewText (); + + bool current_version = true; + foreach (string hash in RevisionHashes) { + Console.WriteLine (hash); + if (current_version) { + revision_combobox.AppendText ("Current Version"); + current_version = false; + } else { + revision_combobox.AppendText (hash); + } + } + + if (position.Equals ("Left")) + revision_combobox.Active = 1; + else if (position.Equals ("Right")) + revision_combobox.Active = 0; + + revision_combobox.Changed += UpdateViews; + + Image icon_previous = new Image (); + icon_previous.IconName = "go-previous"; + Button button_previous = new Button (icon_previous); + if (position.Equals ("Left") && RevisionHashes.Length == 2) + button_previous.State = StateType.Insensitive; + button_previous.Clicked += delegate { + if (revision_combobox.Active + 1 < RevisionHashes.Length) + revision_combobox.Active += 1; + ShowAll (); + }; + + Image icon_next = new Image (); + icon_next.IconName = "go-next"; + Button button_next = new Button (icon_next); + if (position.Equals ("Right")) + button_next.State = StateType.Insensitive; + button_previous.Clicked += delegate { + if (revision_combobox.Active > 0) + revision_combobox.Active -= 1; + ShowAll (); + }; + + controls.PackStart (button_previous, false, false, 0); + controls.PackStart (revision_combobox, false, false, 0); + controls.PackStart (button_next, false, false, 0); + + layout_vertical.PackStart (scrolled_window, true, true, 0); + layout_vertical.PackStart (controls, false, false, 0); + + return layout_vertical; + + } + + + } + + public class RevisionView : VBox + { + + public ScrolledWindow ScrolledWindow; + + public ComboBox ComboBox; + + public Button ButtonPrevious; + public Button ButtonNext; + + private int ValueCount; + private Image Image; + + public RevisionView () : base (false, 6) + { + + Image = new Image (); + + ScrolledWindow = new ScrolledWindow (); + ScrolledWindow.AddWithViewport (Image); + PackStart (ScrolledWindow, true, true, 0); + + HButtonBox controls = new HButtonBox (); + controls.Layout = ButtonBoxStyle.Start; + controls.BorderWidth = 0; + + Image image_previous = new Image (); + image_previous.IconName = "go-previous"; + ButtonPrevious = new Button (image_previous); + + ValueCount = 0; + ComboBox = ComboBox.NewText (); + + Image image_next = new Image (); + image_next.IconName = "go-next"; + ButtonNext = new Button (image_next); + ButtonNext.Clicked += Next; + + controls.Add (ButtonPrevious); + controls.Add (ComboBox); + controls.Add (ButtonNext); + + PackStart (controls, false, false, 0); + + } + + + public void FillComboBox (string [] values) { + + ValueCount = values.Length; + ComboBox.Changed += Update; + + + } + + + public void SetImage (Image image) { + + Image = image; + ShowAll (); + + } + + + public void Update (object o, EventArgs args) { + + Update (); + + } + + + public void Update () { + + if (ComboBox.Active == 0) + ButtonPrevious.State = StateType.Insensitive; + + if (ComboBox.Active + 1 < ValueCount) + ButtonNext.State = StateType.Insensitive; + + } + + + } + +} From b39f498d429cfc8615a26193c9b760f468e7c25d Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Tue, 29 Jun 2010 11:20:58 +0100 Subject: [PATCH 09/16] Continue cleaning up SparkleDiff code --- SparkleShare/SparkleDiff.cs | 112 ++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 61 deletions(-) diff --git a/SparkleShare/SparkleDiff.cs b/SparkleShare/SparkleDiff.cs index 3372d72d..e9a7a36e 100644 --- a/SparkleShare/SparkleDiff.cs +++ b/SparkleShare/SparkleDiff.cs @@ -55,8 +55,8 @@ namespace SparkleShare { private string FilePath; private string FileName; - private VBox ViewLeft; - private VBox ViewRight; + private RevisionView ViewLeft; + private RevisionView ViewRight; private string [] RevisionHashes; @@ -80,8 +80,8 @@ namespace SparkleShare { HBox layout_horizontal = new HBox (false, 12); - ViewLeft = CreateRevisionView ("Left"); - ViewRight = CreateRevisionView ("Right"); + ViewLeft = new RevisionView (); + ViewRight = new RevisionView (); layout_horizontal.PackStart (ViewLeft); layout_horizontal.PackStart (ViewRight); @@ -204,9 +204,6 @@ namespace SparkleShare { private VBox CreateRevisionView (string position) { - VBox layout_vertical = new VBox (false, 6); - - ScrolledWindow scrolled_window = new ScrolledWindow (); Process process = new Process (); process.EnableRaisingEvents = true; @@ -221,16 +218,12 @@ namespace SparkleShare { Gdk.Pixbuf pixbuf; pixbuf = new Gdk.Pixbuf ( (System.IO.Stream) process.StandardOutput.BaseStream); - scrolled_window.AddWithViewport (new Image (pixbuf)); - scrolled_window.Hadjustment.ValueChanged += SyncViewsHorizontally; - scrolled_window.Vadjustment.ValueChanged += SyncViewsVertically; + ViewLeft.ScrolledWindow.Hadjustment.ValueChanged += SyncViewsHorizontally; + ViewLeft.ScrolledWindow.Vadjustment.ValueChanged += SyncViewsVertically; - HBox controls = new HBox (false, 6); - ComboBox revision_combobox = ComboBox.NewText (); - - bool current_version = true; +/* bool current_version = true; foreach (string hash in RevisionHashes) { Console.WriteLine (hash); if (current_version) { @@ -240,63 +233,65 @@ namespace SparkleShare { revision_combobox.AppendText (hash); } } - + if (position.Equals ("Left")) revision_combobox.Active = 1; else if (position.Equals ("Right")) revision_combobox.Active = 0; revision_combobox.Changed += UpdateViews; - - Image icon_previous = new Image (); - icon_previous.IconName = "go-previous"; - Button button_previous = new Button (icon_previous); - if (position.Equals ("Left") && RevisionHashes.Length == 2) - button_previous.State = StateType.Insensitive; - button_previous.Clicked += delegate { - if (revision_combobox.Active + 1 < RevisionHashes.Length) - revision_combobox.Active += 1; - ShowAll (); - }; - - Image icon_next = new Image (); - icon_next.IconName = "go-next"; - Button button_next = new Button (icon_next); - if (position.Equals ("Right")) - button_next.State = StateType.Insensitive; - button_previous.Clicked += delegate { - if (revision_combobox.Active > 0) - revision_combobox.Active -= 1; - ShowAll (); - }; - - controls.PackStart (button_previous, false, false, 0); - controls.PackStart (revision_combobox, false, false, 0); - controls.PackStart (button_next, false, false, 0); - - layout_vertical.PackStart (scrolled_window, true, true, 0); - layout_vertical.PackStart (controls, false, false, 0); - - return layout_vertical; +*/return new VBox (); } } + + + // An image grabbed from a stream generated by Git + public class RevisionImage : Image + { + public string Revision; + public string FilePath; + + public RevisionImage (string file_path, string revision) : base () + { + + Revision = revision; + FilePath = file_path; + + Process process = new Process (); + process.EnableRaisingEvents = true; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + + process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (FilePath); + process.StartInfo.FileName = "git"; + process.StartInfo.Arguments = "show " + revision + ":" + System.IO.Path.GetFileName (FilePath); + process.Start (); + + Pixbuf = new Gdk.Pixbuf ((System.IO.Stream) process.StandardOutput.BaseStream); + + } + + } + + + // A custom widget containing an image view, + // previous/next buttons and a combobox public class RevisionView : VBox { public ScrolledWindow ScrolledWindow; - public ComboBox ComboBox; - public Button ButtonPrevious; public Button ButtonNext; private int ValueCount; private Image Image; + public RevisionView () : base (false, 6) { @@ -320,7 +315,7 @@ namespace SparkleShare { Image image_next = new Image (); image_next.IconName = "go-next"; ButtonNext = new Button (image_next); - ButtonNext.Clicked += Next; +//move outside this class ButtonNext.Clicked += Next; controls.Add (ButtonPrevious); controls.Add (ComboBox); @@ -330,32 +325,27 @@ namespace SparkleShare { } - + + // Fills the widget's combobox with entries public void FillComboBox (string [] values) { ValueCount = values.Length; ComboBox.Changed += Update; - } - + + // Changes the image that is viewed public void SetImage (Image image) { Image = image; ShowAll (); } - - - public void Update (object o, EventArgs args) { - - Update (); - - } - public void Update () { + // Updates the buttons to be disabled or enabled when needed + public void UpdateControls () { if (ComboBox.Active == 0) ButtonPrevious.State = StateType.Insensitive; @@ -364,7 +354,7 @@ namespace SparkleShare { ButtonNext.State = StateType.Insensitive; } - + } From 232d378a09201293361c578cae32bf233799fa61 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 30 Jun 2010 01:08:02 +0100 Subject: [PATCH 10/16] initial commit of SparkleDiff --- {SparkleShare => SparkleDiff}/SparkleDiff.cs | 266 +++++++++---------- 1 file changed, 133 insertions(+), 133 deletions(-) rename {SparkleShare => SparkleDiff}/SparkleDiff.cs (50%) diff --git a/SparkleShare/SparkleDiff.cs b/SparkleDiff/SparkleDiff.cs similarity index 50% rename from SparkleShare/SparkleDiff.cs rename to SparkleDiff/SparkleDiff.cs index e9a7a36e..0aa2d35e 100644 --- a/SparkleShare/SparkleDiff.cs +++ b/SparkleDiff/SparkleDiff.cs @@ -23,20 +23,35 @@ using System.Text.RegularExpressions; namespace SparkleShare { - public class SparkleDiff { public static void Main (string [] args) { - Gtk.Application.Init (); - SparkleDiffWindow sparkle_diff_window; - sparkle_diff_window = new SparkleDiffWindow ("/home/hbons/SparkleShare/Deal/ANDRESDIAZGeorgeWashington.jpg"); - sparkle_diff_window.ShowAll (); + if (args.Length > 0) { - // The main loop - Gtk.Application.Run (); + string file_path = args [0]; + + if (File.Exists (file_path)) { + + Gtk.Application.Init (); + + SparkleDiffWindow sparkle_diff_window; + sparkle_diff_window = new SparkleDiffWindow (file_path); + sparkle_diff_window.ShowAll (); + + // The main loop + Gtk.Application.Run (); + + } else { + + Console.WriteLine ("SparkleDiff: " + file_path + ": No such file or directory."); + Environment.Exit (0); + + } + + } } @@ -52,39 +67,66 @@ namespace SparkleShare { return Catalog.GetString (s); } - private string FilePath; - private string FileName; - private RevisionView ViewLeft; private RevisionView ViewRight; - private string [] RevisionHashes; + private string [] Revisions; public SparkleDiffWindow (string file_path) : base ("") { - FilePath = file_path; - FileName = System.IO.Path.GetFileName (FilePath); + string file_name = System.IO.Path.GetFileName (file_path); SetSizeRequest (1024, 600); SetPosition (WindowPosition.Center); BorderWidth = 12; - Title = String.Format(_("Comparing Versions of ‘{0}’"), System.IO.Path.GetFileName (FilePath)); - IconName = "folder-sparkleshare"; + DeleteEvent += Quit; + + IconName = "image-x-generic"; + Title = String.Format(_("Comparing Revisions of ‘{0}’"), file_name); - GetRevisions (); + Revisions = GetRevisionsForFile (file_path); VBox layout_vertical = new VBox (false, 12); HBox layout_horizontal = new HBox (false, 12); - ViewLeft = new RevisionView (); - ViewRight = new RevisionView (); + ViewLeft = new RevisionView (Revisions); + ViewRight = new RevisionView (Revisions); + + RevisionImage revision_image_left = new RevisionImage (file_path, Revisions [1]); + RevisionImage revision_image_right = new RevisionImage (file_path, Revisions [0]); + + ViewLeft.SetImage (revision_image_left); + ViewRight.SetImage (revision_image_right); + + ViewLeft.ComboBox.Changed += delegate { + + RevisionImage revision_image; + revision_image = new RevisionImage (file_path, Revisions [ViewLeft.ComboBox.Active]); + ViewLeft.SetImage (revision_image); + + HookUpViews (); + + }; + + ViewRight.ComboBox.Changed += delegate { + + RevisionImage revision_image; + revision_image = new RevisionImage (file_path, Revisions [ViewRight.ComboBox.Active]); + ViewRight.SetImage (revision_image); + + HookUpViews (); + + }; + layout_horizontal.PackStart (ViewLeft); layout_horizontal.PackStart (ViewRight); + HookUpViews (); + HButtonBox dialog_buttons = new HButtonBox (); dialog_buttons.Layout = ButtonBoxStyle.End; dialog_buttons.BorderWidth = 0; @@ -104,143 +146,70 @@ namespace SparkleShare { } - private string [] GetRevisions () - { - - Process process = new Process (); - process.EnableRaisingEvents = true; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; - - process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (FilePath); - process.StartInfo.FileName = "git"; - process.StartInfo.Arguments = "log --format=\"%H\" " + FileName; - process.Start (); - - string output = process.StandardOutput.ReadToEnd ().Trim (); - RevisionHashes = Regex.Split (output, "\n"); - - return RevisionHashes; + // Hooks up two views so they will be kept in sync + private void HookUpViews () { + ViewLeft.ScrolledWindow.Hadjustment.ValueChanged += SyncViewsHorizontally; + ViewLeft.ScrolledWindow.Vadjustment.ValueChanged += SyncViewsVertically; + ViewRight.ScrolledWindow.Hadjustment.ValueChanged += SyncViewsHorizontally; + ViewRight.ScrolledWindow.Vadjustment.ValueChanged += SyncViewsVertically; + } + // Keeps the two image views in sync horizontally private void SyncViewsHorizontally (object o, EventArgs args) { - Widget [] view_left_children = ViewLeft.Children; - ScrolledWindow left_scrolled_window = (ScrolledWindow) view_left_children [0]; - - Widget [] view_right_children = ViewRight.Children; - ScrolledWindow right_scrolled_window = (ScrolledWindow) view_right_children [0]; - Adjustment source_adjustment = (Adjustment) o; - if (source_adjustment == left_scrolled_window.Hadjustment) - right_scrolled_window.Hadjustment = source_adjustment; + if (source_adjustment == ViewLeft.ScrolledWindow.Hadjustment) + ViewRight.ScrolledWindow.Hadjustment = source_adjustment; else - left_scrolled_window.Hadjustment = source_adjustment; + ViewLeft.ScrolledWindow.Hadjustment = source_adjustment; } + // Keeps the two image views in sync vertically private void SyncViewsVertically (object o, EventArgs args) { - Widget [] view_left_children = ViewLeft.Children; - ScrolledWindow left_scrolled_window = (ScrolledWindow) view_left_children [0]; - - Widget [] view_right_children = ViewRight.Children; - ScrolledWindow right_scrolled_window = (ScrolledWindow) view_right_children [0]; - Adjustment source_adjustment = (Adjustment) o; - if (source_adjustment == left_scrolled_window.Vadjustment) - right_scrolled_window.Vadjustment = source_adjustment; + if (source_adjustment == ViewLeft.ScrolledWindow.Vadjustment) + ViewRight.ScrolledWindow.Vadjustment = source_adjustment; else - left_scrolled_window.Vadjustment = source_adjustment; + ViewLeft.ScrolledWindow.Vadjustment = source_adjustment; } - - private void UpdateViews (object o, EventArgs args) + // Gets a list of all earlier revisions of this file + private string [] GetRevisionsForFile (string file_path) { - HBox hbox_left = (HBox) ViewLeft.Children [1]; - ComboBox combobox_left = (ComboBox) hbox_left.Children [1]; - string version_left = RevisionHashes [combobox_left.Active]; - - HBox hbox_right = (HBox) ViewRight.Children [1]; - ComboBox combobox_right = (ComboBox) hbox_right.Children [1]; - string version_right = RevisionHashes [combobox_right.Active]; + string file_name = System.IO.Path.GetFileName (file_path); Process process = new Process (); process.EnableRaisingEvents = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; - process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (FilePath); + process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (file_path); process.StartInfo.FileName = "git"; - process.StartInfo.Arguments = "show " + version_left + ":" + FileName; + process.StartInfo.Arguments = "log --format=\"%H\" " + file_name; process.Start (); - Gdk.Pixbuf pixbuf; - pixbuf = new Gdk.Pixbuf ( (System.IO.Stream) process.StandardOutput.BaseStream); + string output = process.StandardOutput.ReadToEnd (); - ViewLeft.Remove (ViewLeft.Children [0]); - ScrolledWindow scrolled_window = new ScrolledWindow (); - scrolled_window.AddWithViewport (new Image (pixbuf)); - - ViewLeft.PackStart (scrolled_window, true, true, 0); - ViewLeft.ReorderChild (scrolled_window, 0); - - scrolled_window.Hadjustment.ValueChanged += SyncViewsHorizontally; - scrolled_window.Vadjustment.ValueChanged += SyncViewsVertically; - - ShowAll (); + return Regex.Split (output.Trim (), "\n"); } - private VBox CreateRevisionView (string position) - { + // Quits the program + private void Quit (object o, EventArgs args) { - - Process process = new Process (); - process.EnableRaisingEvents = true; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; - - process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (FilePath); - process.StartInfo.FileName = "git"; - process.StartInfo.Arguments = "show HEAD:" + FileName; - process.Start (); - - Gdk.Pixbuf pixbuf; - pixbuf = new Gdk.Pixbuf ( (System.IO.Stream) process.StandardOutput.BaseStream); - - - ViewLeft.ScrolledWindow.Hadjustment.ValueChanged += SyncViewsHorizontally; - ViewLeft.ScrolledWindow.Vadjustment.ValueChanged += SyncViewsVertically; - - -/* bool current_version = true; - foreach (string hash in RevisionHashes) { - Console.WriteLine (hash); - if (current_version) { - revision_combobox.AppendText ("Current Version"); - current_version = false; - } else { - revision_combobox.AppendText (hash); - } - } - - if (position.Equals ("Left")) - revision_combobox.Active = 1; - else if (position.Equals ("Right")) - revision_combobox.Active = 0; - - revision_combobox.Changed += UpdateViews; -*/return new VBox (); + Environment.Exit (0); } @@ -291,8 +260,7 @@ namespace SparkleShare { private int ValueCount; private Image Image; - - public RevisionView () : base (false, 6) + public RevisionView (string [] revisions) : base (false, 6) { Image = new Image (); @@ -301,36 +269,60 @@ namespace SparkleShare { ScrolledWindow.AddWithViewport (Image); PackStart (ScrolledWindow, true, true, 0); - HButtonBox controls = new HButtonBox (); - controls.Layout = ButtonBoxStyle.Start; + HBox controls = new HBox (); controls.BorderWidth = 0; Image image_previous = new Image (); image_previous.IconName = "go-previous"; ButtonPrevious = new Button (image_previous); + ButtonPrevious.Clicked += PreviousInComboBox; ValueCount = 0; + ComboBox = ComboBox.NewText (); + foreach (string revision in revisions) { + ComboBox.AppendText (revision); + } + + ComboBox.Active = 0; + + ValueCount = revisions.Length; + Image image_next = new Image (); image_next.IconName = "go-next"; ButtonNext = new Button (image_next); -//move outside this class ButtonNext.Clicked += Next; + ButtonNext.Clicked += NextInComboBox; - controls.Add (ButtonPrevious); + controls.Add (ButtonPrevious); controls.Add (ComboBox); controls.Add (ButtonNext); PackStart (controls, false, false, 0); + UpdateControls (); + + ShowAll (); + } - // Fills the widget's combobox with entries - public void FillComboBox (string [] values) { + public void NextInComboBox (object o, EventArgs args) { - ValueCount = values.Length; - ComboBox.Changed += Update; + if (ComboBox.Active > 0) + ComboBox.Active--; + + UpdateControls (); + + } + + + public void PreviousInComboBox (object o, EventArgs args) { + + if (ComboBox.Active + 1 < ValueCount) + ComboBox.Active++; + + UpdateControls (); } @@ -339,6 +331,11 @@ namespace SparkleShare { public void SetImage (Image image) { Image = image; + Remove (ScrolledWindow); + ScrolledWindow = new ScrolledWindow (); + ScrolledWindow.AddWithViewport (Image); + Add (ScrolledWindow); + ReorderChild (ScrolledWindow, 0); ShowAll (); } @@ -347,14 +344,17 @@ namespace SparkleShare { // Updates the buttons to be disabled or enabled when needed public void UpdateControls () { - if (ComboBox.Active == 0) - ButtonPrevious.State = StateType.Insensitive; - - if (ComboBox.Active + 1 < ValueCount) - ButtonNext.State = StateType.Insensitive; - - } + // TODO: Doesn't work yet. Sleepy -.- + ButtonPrevious.State = StateType.Normal; + ButtonNext.State = StateType.Normal; + if (ComboBox.Active == 0) + ButtonNext.State = StateType.Insensitive; + + if (ComboBox.Active + 1 == ValueCount) + ButtonPrevious.State = StateType.Insensitive; + + } } From 1bbbdb7c81574c37e2ea386a1b54f4ef24248aca Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 30 Jun 2010 01:25:02 +0100 Subject: [PATCH 11/16] Add todo to SparkleDiff --- SparkleDiff/SparkleDiff.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SparkleDiff/SparkleDiff.cs b/SparkleDiff/SparkleDiff.cs index 0aa2d35e..cdd948b3 100644 --- a/SparkleDiff/SparkleDiff.cs +++ b/SparkleDiff/SparkleDiff.cs @@ -194,6 +194,7 @@ namespace SparkleShare { process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; + // TODO: Nice commit summary and "Current Revision" process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (file_path); process.StartInfo.FileName = "git"; process.StartInfo.Arguments = "log --format=\"%H\" " + file_name; @@ -302,8 +303,6 @@ namespace SparkleShare { UpdateControls (); - ShowAll (); - } From 947edeb7a45a8f0c5896abffcfda85add57ed94e Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 30 Jun 2010 01:36:12 +0100 Subject: [PATCH 12/16] Remove notidy-sharp from dependancies in README as it is now bundled --- README | 2 -- 1 file changed, 2 deletions(-) diff --git a/README b/README index 594fb141..007f5b45 100644 --- a/README +++ b/README @@ -34,7 +34,6 @@ SparkleShare currently requires: - gtk-sharp2 >= 2.12.7 - mono-core >= 2.2 - ndesk-dbus >= 0.6 - - notify-sharp >= 0.4.0 - openssh - gvfs >= 1.3 - nautilus-python @@ -63,7 +62,6 @@ To build SparkleShare you need: - monodevelop >= 2.0 - ndesk-dbus-devel >= 0.6 - ndesk-dbus-glib-devel >= 0.6 - - notify-sharp-devel >= 0.4.0 You can build and install SparkleShare like this: From 71dc2eda293d05df1abff4d387a6a766d01039f1 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 30 Jun 2010 12:16:35 +0100 Subject: [PATCH 13/16] [SparkleDiff] Sync scrollbars after changing one of the revisions --- SparkleDiff/SparkleDiff.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SparkleDiff/SparkleDiff.cs b/SparkleDiff/SparkleDiff.cs index cdd948b3..4d3b3c66 100644 --- a/SparkleDiff/SparkleDiff.cs +++ b/SparkleDiff/SparkleDiff.cs @@ -109,6 +109,9 @@ namespace SparkleShare { ViewLeft.SetImage (revision_image); HookUpViews (); + + ViewLeft.ScrolledWindow.Hadjustment = ViewRight.ScrolledWindow.Hadjustment; + ViewLeft.ScrolledWindow.Vadjustment = ViewRight.ScrolledWindow.Vadjustment; }; @@ -120,6 +123,9 @@ namespace SparkleShare { HookUpViews (); + ViewRight.ScrolledWindow.Hadjustment = ViewLeft.ScrolledWindow.Hadjustment; + ViewRight.ScrolledWindow.Vadjustment = ViewLeft.ScrolledWindow.Vadjustment; + }; layout_horizontal.PackStart (ViewLeft); From b3a559fd5f0f1bdef2960687acb53b71c27901bc Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 2 Jul 2010 00:41:38 +0100 Subject: [PATCH 14/16] [sparklediff] nice dates and current version --- SparkleDiff/SparkleDiff.cs | 75 +++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/SparkleDiff/SparkleDiff.cs b/SparkleDiff/SparkleDiff.cs index 4d3b3c66..96ddde6d 100644 --- a/SparkleDiff/SparkleDiff.cs +++ b/SparkleDiff/SparkleDiff.cs @@ -77,7 +77,7 @@ namespace SparkleShare { string file_name = System.IO.Path.GetFileName (file_path); - SetSizeRequest (1024, 600); + SetSizeRequest (800, 540); SetPosition (WindowPosition.Center); BorderWidth = 12; @@ -92,9 +92,45 @@ namespace SparkleShare { VBox layout_vertical = new VBox (false, 12); HBox layout_horizontal = new HBox (false, 12); - - ViewLeft = new RevisionView (Revisions); - ViewRight = new RevisionView (Revisions); + + Process process = new Process (); + process.EnableRaisingEvents = true; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + + // TODO: Nice commit summary and "Current Revision" + process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName (file_path); + process.StartInfo.FileName = "git"; + process.StartInfo.Arguments = "log --format=\"%ct\t%an\" " + file_name; + process.Start (); + + string output = process.StandardOutput.ReadToEnd (); + + string [] revisions_info = Regex.Split (output.Trim (), "\n"); + + int i = 0; + foreach (string revision_info in revisions_info) { + + string [] parts = Regex.Split (revision_info.Trim (), "\t"); + + int timestamp = int.Parse (parts [0]); + string author = parts [1]; + + if (i == 0) + revisions_info [i] = "Current Revision" + "\t" + author; + else + revisions_info [i] = UnixTimestampToDateTime (timestamp).ToString ("d MMM\tH:mm") + + "\t" + author; + + i++; + + } + + ViewLeft = new RevisionView (revisions_info); + ViewRight = new RevisionView (revisions_info); + + ViewLeft.ComboBox.Active = 1; + ViewRight.ComboBox.Active = 0; RevisionImage revision_image_left = new RevisionImage (file_path, Revisions [1]); RevisionImage revision_image_right = new RevisionImage (file_path, Revisions [0]); @@ -112,6 +148,8 @@ namespace SparkleShare { ViewLeft.ScrolledWindow.Hadjustment = ViewRight.ScrolledWindow.Hadjustment; ViewLeft.ScrolledWindow.Vadjustment = ViewRight.ScrolledWindow.Vadjustment; + + ViewLeft.UpdateControls (); }; @@ -126,6 +164,8 @@ namespace SparkleShare { ViewRight.ScrolledWindow.Hadjustment = ViewLeft.ScrolledWindow.Hadjustment; ViewRight.ScrolledWindow.Vadjustment = ViewLeft.ScrolledWindow.Vadjustment; + ViewRight.UpdateControls (); + }; layout_horizontal.PackStart (ViewLeft); @@ -213,6 +253,14 @@ namespace SparkleShare { } + // Converts a UNIX timestamp to a more usable time object + public DateTime UnixTimestampToDateTime (int timestamp) + { + DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0); + return unix_epoch.AddSeconds (timestamp); + } + + // Quits the program private void Quit (object o, EventArgs args) { @@ -276,7 +324,7 @@ namespace SparkleShare { ScrolledWindow.AddWithViewport (Image); PackStart (ScrolledWindow, true, true, 0); - HBox controls = new HBox (); + HBox controls = new HBox (false, 6); controls.BorderWidth = 0; Image image_previous = new Image (); @@ -301,9 +349,9 @@ namespace SparkleShare { ButtonNext = new Button (image_next); ButtonNext.Clicked += NextInComboBox; - controls.Add (ButtonPrevious); - controls.Add (ComboBox); - controls.Add (ButtonNext); +// controls.PackStart (ButtonPrevious, false, false, 0); + controls.PackStart (ComboBox, false, false, 0); +// controls.PackStart (ButtonNext, false, false, 0); PackStart (controls, false, false, 0); @@ -314,21 +362,21 @@ namespace SparkleShare { public void NextInComboBox (object o, EventArgs args) { - if (ComboBox.Active > 0) +/* if (ComboBox.Active > 0) ComboBox.Active--; UpdateControls (); - +*/ } public void PreviousInComboBox (object o, EventArgs args) { - if (ComboBox.Active + 1 < ValueCount) +/* if (ComboBox.Active + 1 < ValueCount) ComboBox.Active++; UpdateControls (); - +*/ } @@ -350,7 +398,7 @@ namespace SparkleShare { public void UpdateControls () { // TODO: Doesn't work yet. Sleepy -.- - ButtonPrevious.State = StateType.Normal; +/* ButtonPrevious.State = StateType.Normal; ButtonNext.State = StateType.Normal; if (ComboBox.Active == 0) @@ -358,6 +406,7 @@ namespace SparkleShare { if (ComboBox.Active + 1 == ValueCount) ButtonPrevious.State = StateType.Insensitive; +*/ } From 563ef30693f93b8098d8e7497ede845d554ed527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Sat, 3 Jul 2010 09:39:28 +0200 Subject: [PATCH 15/16] Add SparkleDiff to the build system --- Makefile.am | 1 + SparkleDiff/Makefile.am | 10 ++++++++++ build/build.environment.mk | 4 ++++ configure.ac | 2 ++ 4 files changed, 17 insertions(+) create mode 100644 SparkleDiff/Makefile.am diff --git a/Makefile.am b/Makefile.am index a55ddf4d..4e58475b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,7 @@ SUBDIRS = \ build \ notify-sharp \ SparkleShare \ + SparkleDiff \ data \ po diff --git a/SparkleDiff/Makefile.am b/SparkleDiff/Makefile.am new file mode 100644 index 00000000..0f90c96b --- /dev/null +++ b/SparkleDiff/Makefile.am @@ -0,0 +1,10 @@ +ASSEMBLY = SparkleDiff +TARGET = exe + +LINK = $(REF_SPARKLEDIFF) + +SOURCES = \ +$(top_srcdir)/SparkleShare/Defines.cs \ +SparkleDiff.cs + +include $(top_srcdir)/build/build.mk diff --git a/build/build.environment.mk b/build/build.environment.mk index 0c8fe3d8..b3c75395 100644 --- a/build/build.environment.mk +++ b/build/build.environment.mk @@ -34,6 +34,10 @@ REF_SPARKLESHARE = $(LINK_SYSTEM) $(LINK_GTK) $(LINK_DBUS) $(LINK_NOTIFY_SHARP_D LINK_SPARKLESHARE = -r:$(DIR_BIN)/SparkleShare.exe LINK_SPARKLESHARE_DEPS = $(REF_SPARKLESHARE) $(LINK_SPARKLESHARE) +REF_SPARKLEDIFF = $(LINK_SYSTEM) $(LINK_GTK) $(LINK_DBUS) $(LINK_MONO_POSIX) +LINK_SPARKLEDIFF = -r:$(DIR_BIN)/SparkleShare.exe +LINK_SPARKLEDIFF_DEPS = $(REF_SPARKLEDIFF) $(LINK_SPARKLEDIFF) + # Cute hack to replace a space with something colon:= : empty:= diff --git a/configure.ac b/configure.ac index 0e8f8f31..02d5bed3 100644 --- a/configure.ac +++ b/configure.ac @@ -89,6 +89,8 @@ build/m4/shave/shave-libtool data/Makefile data/icons/Makefile notify-sharp/Makefile +SparkleDiff/Makefile +SparkleDiff/Defines.cs SparkleShare/sparkleshare SparkleShare/Defines.cs SparkleShare/AssemblyInfo.cs From 975ea18375778d2e184e3c4a6093f7feab64654f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Sat, 3 Jul 2010 09:50:02 +0200 Subject: [PATCH 16/16] Fixup i18n of SparkleDiff --- SparkleDiff/SparkleDiff.cs | 7 +++++-- po/POTFILES.in | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SparkleDiff/SparkleDiff.cs b/SparkleDiff/SparkleDiff.cs index 96ddde6d..878ee038 100644 --- a/SparkleDiff/SparkleDiff.cs +++ b/SparkleDiff/SparkleDiff.cs @@ -28,6 +28,7 @@ namespace SparkleShare { public static void Main (string [] args) { + Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR); if (args.Length > 0) { @@ -85,6 +86,7 @@ namespace SparkleShare { DeleteEvent += Quit; IconName = "image-x-generic"; + // TRANSLATORS: The parameter is a filename Title = String.Format(_("Comparing Revisions of ‘{0}’"), file_name); Revisions = GetRevisionsForFile (file_path); @@ -117,9 +119,10 @@ namespace SparkleShare { string author = parts [1]; if (i == 0) - revisions_info [i] = "Current Revision" + "\t" + author; + revisions_info [i] = _("Current Revision") + "\t" + author; else - revisions_info [i] = UnixTimestampToDateTime (timestamp).ToString ("d MMM\tH:mm") + + // TRANSLATORS: This is a format specifier according to System.Globalization.DateTimeFormatInfo + revisions_info [i] = UnixTimestampToDateTime (timestamp).ToString (_("d MMM\tH:mm")) + "\t" + author; i++; diff --git a/po/POTFILES.in b/po/POTFILES.in index ad84be9b..0a11dd8e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -2,6 +2,7 @@ # Please keep this file in alphabetical order; run ./sort-potfiles # after adding files here. [encoding: UTF-8] +SparkleDiff/SparkleDiff.cs SparkleShare/SparkleBubble.cs SparkleShare/SparkleDialog.cs SparkleShare/SparkleHelpers.cs