From 6846fad75f811433f5d977f618d2f5b7d5d40388 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 20 May 2010 20:38:10 +0100 Subject: [PATCH] fix bug where all repo menu items open the same window --- SparkleShare/SparkleStatusIcon.cs | 143 ++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 SparkleShare/SparkleStatusIcon.cs diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs new file mode 100644 index 00000000..f93175c0 --- /dev/null +++ b/SparkleShare/SparkleStatusIcon.cs @@ -0,0 +1,143 @@ +// 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 SparkleShare; +using System; +using System.IO; +using System.Diagnostics; + +namespace SparkleShare { + + public class SparkleStatusIcon : StatusIcon { + + // Short alias for the translations + public static string _ (string s) { + return Catalog.GetString (s); + } + + public EventHandler CreateWindowDelegate (SparkleRepo SparkleRepo) { + return delegate { + SparkleWindow SparkleWindow = new SparkleWindow (SparkleRepo); + SparkleWindow.ShowAll (); + }; + } + + public SparkleStatusIcon () : base () { + + Activate += delegate { + + Menu Menu = new Menu(); + + MenuItem StatusItem = new MenuItem (_("Everything is up to date")); + StatusItem.Sensitive = false; + Menu.Add (StatusItem); + Menu.Add (new SeparatorMenuItem ()); + + MenuItem [] FolderItems = + new MenuItem [SparkleShare.Repositories.Length]; + + int i = 0; + foreach (SparkleRepo SparkleRepo in SparkleShare.Repositories) { + FolderItems [i] = new MenuItem (SparkleRepo.Name); + FolderItems [i].Activated += CreateWindowDelegate (SparkleRepo); + Menu.Add (FolderItems [i]); + i++; + } + + MenuItem AddItem = new MenuItem (_("Add a Folder…")); + AddItem.Activated += delegate { + SparkleDialog SparkleDialog = new SparkleDialog (); + SparkleDialog.ShowAll (); + }; + Menu.Add (AddItem); + Menu.Add (new SeparatorMenuItem ()); + + CheckMenuItem NotifyCheckMenuItem = + new CheckMenuItem (_("Show notifications")); + Menu.Add (NotifyCheckMenuItem); + Menu.Add (new SeparatorMenuItem ()); + + string NotifyChangesFileName = + SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, + "sparkleshare.notify"); + + if (System.IO.File.Exists (NotifyChangesFileName)) + NotifyCheckMenuItem.Active = true; + + NotifyCheckMenuItem.Toggled += delegate { + if (System.IO.File.Exists (NotifyChangesFileName)) { + File.Delete (NotifyChangesFileName); + } else { + System.IO.File.Create (NotifyChangesFileName); + } + }; + + MenuItem OpenFolderItem = new MenuItem (_("Open Sharing Folder")); + OpenFolderItem.Activated += delegate { + Process Process = new Process (); + Process.StartInfo.FileName = "xdg-open"; + Process.StartInfo.Arguments = SparklePaths.SparklePath; + Process.Start(); + }; + Menu.Add (OpenFolderItem); + + MenuItem AboutItem = new MenuItem (_("Visit SparkleShare Website")); + AboutItem.Activated += delegate { + Process Process = new Process (); + Process.StartInfo.FileName = "xdg-open"; + Process.StartInfo.Arguments = "http://www.sparkleshare.org/"; + Process.Start(); + }; + Menu.Add (AboutItem); + + Menu.Add (new SeparatorMenuItem ()); + MenuItem QuitItem = new MenuItem ("Quit"); + QuitItem.Activated += delegate { Environment.Exit (0); }; + Menu.Add (QuitItem); + + Menu.ShowAll (); + Menu.Popup (); + + }; + + SetIdleState (); + + } + + public void SetIdleState () { + IconName = "folder-sparkleshare"; + } + + public void SetSyncingState () { +// IconName = "folder-syncing"; + } + + public void SetErrorState () { +// IconName = "folder-sync-error"; + } + + // Quits the program + public void Quit (object o, EventArgs args) { + System.IO.File.Delete (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath + + "sparkleshare.pid")); + Application.Quit (); + } + + } + +}