separate dialog class and make field checking work
This commit is contained in:
parent
afc2701105
commit
cc2043b5db
163
SparkleShare/SparkleDialog.cs
Normal file
163
SparkleShare/SparkleDialog.cs
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
// SparkleShare, an instant update workflow to Git.
|
||||||
|
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||||
|
//
|
||||||
|
// 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using Gtk;
|
||||||
|
using SparkleShare;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace SparkleShare {
|
||||||
|
|
||||||
|
// A dialog where the user can enter a folder
|
||||||
|
// name and url to sync changes with
|
||||||
|
public class SparkleDialog : Window {
|
||||||
|
|
||||||
|
private Button AddButton;
|
||||||
|
private ComboBoxEntry RemoteUrlCombo;
|
||||||
|
private Entry NameEntry;
|
||||||
|
private SparkleWindow ParentSparkleWindow;
|
||||||
|
|
||||||
|
public SparkleDialog (SparkleWindow Parent) : base ("") {
|
||||||
|
|
||||||
|
ParentSparkleWindow = Parent;
|
||||||
|
BorderWidth = 6;
|
||||||
|
IconName = "folder-sparkleshare";
|
||||||
|
Modal = true;
|
||||||
|
Resizable = false;
|
||||||
|
SetPosition (WindowPosition.Center);
|
||||||
|
Title = "Add Folder";
|
||||||
|
TransientFor = ParentSparkleWindow;
|
||||||
|
|
||||||
|
VBox VBox = new VBox (false, 0);
|
||||||
|
|
||||||
|
Label NameLabel = new Label ("Folder Name: ");
|
||||||
|
NameEntry = new Entry ();
|
||||||
|
Label NameExample = new Label ("<span size='small'><i>Example: " +
|
||||||
|
"‘Project’.</i></span>");
|
||||||
|
NameExample.UseMarkup = true;
|
||||||
|
NameExample.SetAlignment (0, 0);
|
||||||
|
NameLabel.Xalign = 1;
|
||||||
|
|
||||||
|
Label RemoteUrlLabel = new Label ("Remote address: ");
|
||||||
|
|
||||||
|
string [] DefaultUrls = new string [4] { "ssh://git@github.com/",
|
||||||
|
"ssh://git@git.gnome.org/",
|
||||||
|
"ssh://git@fedorahosted.org/",
|
||||||
|
"ssh://git@gitorious.org/" };
|
||||||
|
|
||||||
|
RemoteUrlCombo = new ComboBoxEntry (DefaultUrls);
|
||||||
|
|
||||||
|
Label RemoteUrlExample = new Label ("<span size='small'><i>Example: " +
|
||||||
|
"‘ssh://git@github.com/’.</i></span>");
|
||||||
|
RemoteUrlExample.UseMarkup = true;
|
||||||
|
RemoteUrlExample.SetAlignment (0, 0);
|
||||||
|
RemoteUrlLabel.Xalign = 1;
|
||||||
|
|
||||||
|
HButtonBox ButtonBox = new HButtonBox ();
|
||||||
|
ButtonBox.Layout = ButtonBoxStyle.End;
|
||||||
|
ButtonBox.Spacing = 6;
|
||||||
|
ButtonBox.BorderWidth = 6;
|
||||||
|
|
||||||
|
AddButton = new Button (Stock.Add);
|
||||||
|
Button CancelButton = new Button (Stock.Cancel);
|
||||||
|
|
||||||
|
CancelButton.Clicked += delegate {
|
||||||
|
Destroy ();
|
||||||
|
};
|
||||||
|
|
||||||
|
RemoteUrlCombo.Entry.Changed += CheckFields;
|
||||||
|
NameEntry.Changed += CheckFields;
|
||||||
|
|
||||||
|
AddButton.Sensitive = false;
|
||||||
|
AddButton.Clicked += CloneRepo;
|
||||||
|
|
||||||
|
ButtonBox.Add (CancelButton);
|
||||||
|
ButtonBox.Add (AddButton);
|
||||||
|
|
||||||
|
Table Table = new Table(4, 2, false);
|
||||||
|
Table.RowSpacing = 6;
|
||||||
|
Table.BorderWidth = 6;
|
||||||
|
Table.Attach (NameLabel, 0, 1, 0, 1);
|
||||||
|
|
||||||
|
Table.Attach (NameEntry, 1, 2, 0, 1);
|
||||||
|
Table.Attach (NameExample, 1, 2, 1, 2);
|
||||||
|
Table.Attach (RemoteUrlLabel, 0, 1, 3, 4);
|
||||||
|
Table.Attach (RemoteUrlCombo, 1, 2, 3, 4);
|
||||||
|
Table.Attach (RemoteUrlExample, 1, 2, 4, 5);
|
||||||
|
|
||||||
|
VBox.PackStart (Table, false, false, 0);
|
||||||
|
VBox.PackStart (ButtonBox, false, false, 0);
|
||||||
|
|
||||||
|
Add (VBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CloneRepo (object o, EventArgs args) {
|
||||||
|
|
||||||
|
Remove (Child);
|
||||||
|
VBox Box = new VBox (false, 24);
|
||||||
|
SparkleSpinner Spinner = new SparkleSpinner ();
|
||||||
|
Label Label = new Label ("Downloading files,\n" +
|
||||||
|
"this may take a while...");
|
||||||
|
Box.PackStart (Spinner, false, false, 0);
|
||||||
|
Box.PackStart (Label, false, false, 0);
|
||||||
|
BorderWidth = 30;
|
||||||
|
Add (Box);
|
||||||
|
|
||||||
|
string RepoRemoteUrl = RemoteUrlCombo.Entry.Text;
|
||||||
|
string RepoName = NameEntry.Text;
|
||||||
|
|
||||||
|
Process Process = new Process();
|
||||||
|
Process.EnableRaisingEvents = true;
|
||||||
|
Process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
Process.StartInfo.UseShellExecute = false;
|
||||||
|
Process.StartInfo.FileName = "git";
|
||||||
|
Process.StartInfo.WorkingDirectory =
|
||||||
|
SparklePaths.SparkleTmpPath;
|
||||||
|
|
||||||
|
Process.StartInfo.Arguments = "clone " +
|
||||||
|
RepoRemoteUrl + " " +
|
||||||
|
RepoName;
|
||||||
|
|
||||||
|
Process.Start ();
|
||||||
|
Process.Exited += delegate {
|
||||||
|
Directory.Move (
|
||||||
|
SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath,
|
||||||
|
RepoName),
|
||||||
|
SparkleHelpers.CombineMore (SparklePaths.SparklePath,
|
||||||
|
RepoName)
|
||||||
|
);
|
||||||
|
Destroy ();
|
||||||
|
ParentSparkleWindow.ToggleVisibility ();
|
||||||
|
ParentSparkleWindow.Notebook.CurrentPage = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enables the Add button when the fields are
|
||||||
|
// filled in correctly
|
||||||
|
public void CheckFields (object o, EventArgs args) {
|
||||||
|
if (SparkleHelpers.IsGitUrl (RemoteUrlCombo.Entry.Text)
|
||||||
|
&& NameEntry.Text.Length > 0)
|
||||||
|
AddButton.Sensitive = true;
|
||||||
|
else
|
||||||
|
AddButton.Sensitive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -98,7 +98,7 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsGitUrl (string Url) {
|
public static bool IsGitUrl (string Url) {
|
||||||
return Regex.Match (Url, @"^(ssh://|git://)*(/|:)*").Success;
|
return Regex.Match (Url, @"[a-z]+://.+(/|:).+").Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ namespace SparkleShare {
|
||||||
|
|
||||||
// Check if git is installed
|
// Check if git is installed
|
||||||
Process Process = new Process();
|
Process Process = new Process();
|
||||||
|
Process.StartInfo.FileName = "git";
|
||||||
Process.StartInfo.RedirectStandardOutput = true;
|
Process.StartInfo.RedirectStandardOutput = true;
|
||||||
Process.StartInfo.UseShellExecute = false;
|
Process.StartInfo.UseShellExecute = false;
|
||||||
Process.StartInfo.FileName = "git";
|
|
||||||
Process.Start();
|
Process.Start();
|
||||||
|
|
||||||
if (Process.StandardOutput.ReadToEnd().IndexOf ("version") == -1) {
|
if (Process.StandardOutput.ReadToEnd().IndexOf ("version") == -1) {
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="SparkleBubble.cs" />
|
<Compile Include="SparkleBubble.cs" />
|
||||||
|
<Compile Include="SparkleDialog.cs" />
|
||||||
<Compile Include="SparkleHelpers.cs" />
|
<Compile Include="SparkleHelpers.cs" />
|
||||||
<Compile Include="SparklePaths.cs" />
|
<Compile Include="SparklePaths.cs" />
|
||||||
<Compile Include="SparklePlatform.cs" />
|
<Compile Include="SparklePlatform.cs" />
|
||||||
|
|
|
@ -31,10 +31,11 @@ namespace SparkleShare {
|
||||||
private VBox LayoutVerticalRight;
|
private VBox LayoutVerticalRight;
|
||||||
private HBox LayoutHorizontal;
|
private HBox LayoutHorizontal;
|
||||||
|
|
||||||
private Notebook Notebook;
|
public Notebook Notebook;
|
||||||
private TreeView ReposView;
|
private TreeView ReposView;
|
||||||
private ListStore ReposStore;
|
private ListStore ReposStore;
|
||||||
private SparkleRepo [] Repositories;
|
private SparkleRepo [] Repositories;
|
||||||
|
private SparkleDialog SparkleDialog;
|
||||||
|
|
||||||
public SparkleWindow (SparkleRepo [] R) : base ("SparkleShare") {
|
public SparkleWindow (SparkleRepo [] R) : base ("SparkleShare") {
|
||||||
|
|
||||||
|
@ -50,7 +51,11 @@ namespace SparkleShare {
|
||||||
|
|
||||||
NoFoldersBubble.IconName = "folder-sparkleshare";
|
NoFoldersBubble.IconName = "folder-sparkleshare";
|
||||||
NoFoldersBubble.AddAction ("", "Set up a folder",
|
NoFoldersBubble.AddAction ("", "Set up a folder",
|
||||||
delegate { CreateAddDialog (); } );
|
delegate {
|
||||||
|
SparkleDialog =
|
||||||
|
new SparkleDialog (this);
|
||||||
|
SparkleDialog.ShowAll ();
|
||||||
|
} );
|
||||||
|
|
||||||
} else CreateWindow ();
|
} else CreateWindow ();
|
||||||
|
|
||||||
|
@ -192,7 +197,8 @@ namespace SparkleShare {
|
||||||
Button AddButton = new Button ("Add...");
|
Button AddButton = new Button ("Add...");
|
||||||
|
|
||||||
AddButton.Clicked += delegate {
|
AddButton.Clicked += delegate {
|
||||||
CreateAddDialog ();
|
SparkleDialog = new SparkleDialog (this);
|
||||||
|
SparkleDialog.ShowAll ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -436,127 +442,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateAddDialog () {
|
// Shows or hides the window
|
||||||
|
|
||||||
Window AddDialog = new Window ("");
|
|
||||||
AddDialog.SetPosition (WindowPosition.Center);
|
|
||||||
AddDialog.Modal = true;
|
|
||||||
AddDialog.TransientFor = this;
|
|
||||||
AddDialog.BorderWidth = 6;
|
|
||||||
AddDialog.IconName = "folder-sparkleshare";
|
|
||||||
|
|
||||||
VBox VBox = new VBox (false, 0);
|
|
||||||
|
|
||||||
Label NameLabel = new Label ("Folder Name: ");
|
|
||||||
Entry NameEntry = new Entry ();
|
|
||||||
Label NameExample = new Label ("<span size='small'><i>Example: ‘Project’.</i></span>");
|
|
||||||
NameExample.UseMarkup = true;
|
|
||||||
NameExample.SetAlignment (0, 0);
|
|
||||||
NameLabel.Xalign = 1;
|
|
||||||
|
|
||||||
Label RemoteUrlLabel = new Label ("Remote address: ");
|
|
||||||
|
|
||||||
string [] DefaultUrls = new string [4] { "ssh://git@github.com/",
|
|
||||||
"ssh://git@git.gnome.org/",
|
|
||||||
"ssh://git@fedorahosted.org/",
|
|
||||||
"ssh://git@gitorious.org/" };
|
|
||||||
|
|
||||||
ComboBoxEntry RemoteUrlCombo = new ComboBoxEntry (DefaultUrls);
|
|
||||||
|
|
||||||
Label RemoteUrlExample = new Label ("<span size='small'><i>Example: ‘ssh://git@github.com/’.</i></span>");
|
|
||||||
RemoteUrlExample.UseMarkup = true;
|
|
||||||
RemoteUrlExample.SetAlignment (0, 0);
|
|
||||||
RemoteUrlLabel.Xalign = 1;
|
|
||||||
|
|
||||||
// NameEntry.Text;
|
|
||||||
|
|
||||||
HButtonBox ButtonBox = new HButtonBox ();
|
|
||||||
ButtonBox.Layout = ButtonBoxStyle.End;
|
|
||||||
ButtonBox.Spacing = 6;
|
|
||||||
ButtonBox.BorderWidth = 6;
|
|
||||||
|
|
||||||
Button AddButton = new Button (Stock.Add);
|
|
||||||
Button CancelButton = new Button (Stock.Cancel);
|
|
||||||
|
|
||||||
CancelButton.Clicked += delegate {
|
|
||||||
AddDialog.Destroy ();
|
|
||||||
};
|
|
||||||
|
|
||||||
AddButton.State = StateType.Insensitive;
|
|
||||||
AddButton.Clicked += delegate {
|
|
||||||
RemoteUrlCombo.Entry.Changed += delegate {
|
|
||||||
if (SparkleHelpers.IsGitUrl (RemoteUrlCombo.Entry.Text))
|
|
||||||
AddButton.State = StateType.Normal;
|
|
||||||
};
|
|
||||||
|
|
||||||
RemoteUrlCombo.Entry.Changed += delegate {
|
|
||||||
if (RemoteUrlCombo.Entry.Text.Length > 0)
|
|
||||||
AddButton.State = StateType.Normal;
|
|
||||||
};
|
|
||||||
|
|
||||||
AddDialog.Remove (AddDialog.Child);
|
|
||||||
VBox Box = new VBox (false, 24);
|
|
||||||
SparkleSpinner Spinner = new SparkleSpinner ();
|
|
||||||
Label Label = new Label ("Downloading files,\n" +
|
|
||||||
"this may take a while...");
|
|
||||||
Box.PackStart (Spinner, false, false, 0);
|
|
||||||
Box.PackStart (Label, false, false, 0);
|
|
||||||
AddDialog.BorderWidth = 30;
|
|
||||||
AddDialog.Add (Box);
|
|
||||||
AddDialog.ShowAll ();
|
|
||||||
|
|
||||||
string RepoRemoteUrl = RemoteUrlCombo.Entry.Text;
|
|
||||||
string RepoName = NameEntry.Text;
|
|
||||||
|
|
||||||
Process Process = new Process();
|
|
||||||
Process.EnableRaisingEvents = true;
|
|
||||||
Process.StartInfo.RedirectStandardOutput = true;
|
|
||||||
Process.StartInfo.UseShellExecute = false;
|
|
||||||
Process.StartInfo.FileName = "git";
|
|
||||||
Process.StartInfo.WorkingDirectory =
|
|
||||||
SparklePaths.SparkleTmpPath;
|
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "clone " +
|
|
||||||
RepoRemoteUrl + " " +
|
|
||||||
RepoName;
|
|
||||||
|
|
||||||
Process.Start ();
|
|
||||||
Process.Exited += delegate {
|
|
||||||
Directory.Move (
|
|
||||||
SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath,
|
|
||||||
RepoName),
|
|
||||||
SparkleHelpers.CombineMore (SparklePaths.SparklePath,
|
|
||||||
RepoName)
|
|
||||||
);
|
|
||||||
AddDialog.Destroy ();
|
|
||||||
ToggleVisibility ();
|
|
||||||
Notebook.CurrentPage = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
ButtonBox.Add (CancelButton);
|
|
||||||
ButtonBox.Add (AddButton);
|
|
||||||
|
|
||||||
Table Table = new Table(4, 2, false);
|
|
||||||
Table.RowSpacing = 6;
|
|
||||||
Table.BorderWidth = 6;
|
|
||||||
Table.Attach (NameLabel, 0, 1, 0, 1);
|
|
||||||
|
|
||||||
Table.Attach (NameEntry, 1, 2, 0, 1);
|
|
||||||
Table.Attach (NameExample, 1, 2, 1, 2);
|
|
||||||
Table.Attach (RemoteUrlLabel, 0, 1, 3, 4);
|
|
||||||
Table.Attach (RemoteUrlCombo, 1, 2, 3, 4);
|
|
||||||
Table.Attach (RemoteUrlExample, 1, 2, 4, 5);
|
|
||||||
|
|
||||||
VBox.PackStart (Table, false, false, 0);
|
|
||||||
VBox.PackStart (ButtonBox, false, false, 0);
|
|
||||||
|
|
||||||
AddDialog.Add (VBox);
|
|
||||||
AddDialog.ShowAll ();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ToggleVisibility() {
|
public void ToggleVisibility() {
|
||||||
if (Repositories.Length > 0) {
|
if (Repositories.Length > 0) {
|
||||||
Present ();
|
Present ();
|
||||||
|
@ -566,9 +452,10 @@ namespace SparkleShare {
|
||||||
} else {
|
} else {
|
||||||
ShowAll ();
|
ShowAll ();
|
||||||
}
|
}
|
||||||
} else CreateAddDialog ();
|
} else SparkleDialog = new SparkleDialog (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Quits the program
|
||||||
public void Quit (object o, EventArgs args) {
|
public void Quit (object o, EventArgs args) {
|
||||||
File.Delete (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath +
|
File.Delete (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath +
|
||||||
"sparkleshare.pid"));
|
"sparkleshare.pid"));
|
||||||
|
|
Loading…
Reference in a new issue