mirror of
https://github.com/abdelkader/vCardEditor
synced 2025-12-12 08:27:19 +07:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7c66075a1 | ||
|
|
c4a29b678f | ||
|
14efe79576
|
|||
|
|
66a77f3b98 | ||
| 5f33b3adaf | |||
|
|
90dce429bd | ||
|
|
b17fce8dde | ||
|
|
afe52e2b18 | ||
|
|
c89d9a197c | ||
|
|
6b57814c5b | ||
|
|
2023043889 | ||
|
|
4401f13fb4 | ||
|
|
c9b9dfb623 |
@@ -44,6 +44,9 @@ namespace VCFEditor.Model
|
||||
|
||||
[Browsable(false)]
|
||||
public bool isDeleted { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public string path { get; set; }
|
||||
|
||||
|
||||
public Contact()
|
||||
@@ -53,6 +56,18 @@ namespace VCFEditor.Model
|
||||
isDirty = false;
|
||||
}
|
||||
|
||||
public Contact(vCard card)
|
||||
{
|
||||
this.card = card;
|
||||
isSelected = false;
|
||||
isDirty = false;
|
||||
}
|
||||
|
||||
public Contact(string path) : this()
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
private void NotifyPropertyChanged(string name)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace VCFEditor.Presenter
|
||||
|
||||
_view.LoadForm += LoadFormHandler;
|
||||
_view.AddContact += AddContactHandler;
|
||||
_view.NewFileOpened += NewFileOpenedHandler;
|
||||
_view.NewFileOpened += OpenNewFileHandler;
|
||||
_view.SaveContactsSelected += SaveContactsHandler;
|
||||
_view.ChangeContactsSelected += ChangeContactSelectedHandler;
|
||||
_view.DeleteContact += DeleteContactHandler;
|
||||
@@ -42,9 +42,74 @@ namespace VCFEditor.Presenter
|
||||
_view.CountImagesEvent += _view_CountImages;
|
||||
_view.ClearImagesEvent += _view_ClearImages;
|
||||
_view.BatchExportImagesEvent += _view_BatchExportImagesEvent;
|
||||
_view.SplitFileEvent += SaveSplittedFileHandler;
|
||||
_view.OpenFolderEvent += OpenNewFolderHandler;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OpenNewFolderHandler(object sender, EventArg<string> e)
|
||||
{
|
||||
BeforeOpeningNewFileHandler();
|
||||
|
||||
string path = e.Data;
|
||||
if (string.IsNullOrEmpty(path))
|
||||
path = _view.DisplayOpenFolderDialog();
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
var Loaded =_repository.LoadMultipleFilesContact(path);
|
||||
if (!Loaded)
|
||||
{
|
||||
_view.DisplayMessage("No file loaded!", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
AddPathToMostRecentUsedFiles(path);
|
||||
_view.DisplayContacts(_repository.Contacts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OpenNewFileHandler(object sender, EventArg<string> e)
|
||||
{
|
||||
BeforeOpeningNewFileHandler();
|
||||
|
||||
string path = e.Data;
|
||||
if (string.IsNullOrEmpty(path))
|
||||
path = _view.DisplayOpenFileDialog("vCard Files|*.vcf");
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
string ext = _repository.GetExtension(path);
|
||||
if (!string.Equals(ext, ".vcf", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_view.DisplayMessage("Only vcf extension accepted!", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!_repository.LoadContacts(path))
|
||||
_view.DisplayMessage("File seems missing or corrupted!", "Error");
|
||||
else
|
||||
{
|
||||
_view.DisplayContacts(_repository.Contacts);
|
||||
AddPathToMostRecentUsedFiles(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private void AddPathToMostRecentUsedFiles(string path)
|
||||
{
|
||||
FixedList MostRecentUsedFiles = ConfigRepository.Instance.Paths;
|
||||
if (!MostRecentUsedFiles.Contains(path))
|
||||
{
|
||||
MostRecentUsedFiles.Enqueue(path);
|
||||
_view.UpdateMRUMenu(MostRecentUsedFiles);
|
||||
}
|
||||
}
|
||||
private void _view_BatchExportImagesEvent(object sender, EventArgs e)
|
||||
{
|
||||
if (_repository.Contacts == null || _repository.Contacts.Count == 0)
|
||||
@@ -129,7 +194,7 @@ namespace VCFEditor.Presenter
|
||||
if (paths.Length > 1)
|
||||
{
|
||||
var evt = new EventArg<string>(paths[1]);
|
||||
NewFileOpenedHandler(sender, evt);
|
||||
OpenNewFileHandler(sender, evt);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -247,6 +312,7 @@ namespace VCFEditor.Presenter
|
||||
private void AddContactHandler(object sender, EventArgs e)
|
||||
{
|
||||
_repository.AddEmptyContact();
|
||||
_view.DisplayContacts(_repository.Contacts);
|
||||
}
|
||||
|
||||
private void DeleteContactHandler(object sender, EventArgs e)
|
||||
@@ -256,8 +322,29 @@ namespace VCFEditor.Presenter
|
||||
|
||||
private void SaveContactsHandler(object sender, EventArgs e)
|
||||
{
|
||||
string filename;
|
||||
if (!string.IsNullOrEmpty(_repository.fileName))
|
||||
_repository.SaveContactsToFile(_repository.fileName);
|
||||
filename = _repository.fileName;
|
||||
else
|
||||
filename = _view.DisplaySaveDialog("");
|
||||
|
||||
|
||||
_repository.SaveContactsToFile(filename);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void SaveSplittedFileHandler(object sender, EventArgs e)
|
||||
{
|
||||
if (_repository.Contacts == null || _repository.Contacts.Count == 0)
|
||||
return;
|
||||
|
||||
string Path = _view.DisplayOpenFolderDialog();
|
||||
if (!string.IsNullOrEmpty(Path))
|
||||
{
|
||||
int count = _repository.SaveSplittedFiles(Path);
|
||||
_view.DisplayMessage(string.Format("{0} contact(s) processed!", count), "Information");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -266,42 +353,12 @@ namespace VCFEditor.Presenter
|
||||
if (_repository.Contacts != null && _repository.dirty)
|
||||
{
|
||||
if (!_view.AskMessage("Save current file before?", "Load"))
|
||||
_repository.SaveContactsToFile(_repository.fileName);
|
||||
SaveContactsHandler(null, null);
|
||||
//_repository.SaveContactsToFile(_repository.fileName);
|
||||
}
|
||||
|
||||
}
|
||||
public void NewFileOpenedHandler(object sender, EventArg<string> e)
|
||||
{
|
||||
BeforeOpeningNewFileHandler();
|
||||
|
||||
string path = e.Data;
|
||||
if (string.IsNullOrEmpty(path))
|
||||
path = _view.DisplayOpenDialog("vCard Files|*.vcf");
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
string ext = _repository.GetExtension(path);
|
||||
if (!string.Equals(ext, ".vcf", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_view.DisplayMessage("Only vcf extension accepted!", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
FixedList MostRecentUsedFiles = ConfigRepository.Instance.Paths;
|
||||
if (!MostRecentUsedFiles.Contains(path))
|
||||
{
|
||||
MostRecentUsedFiles.Enqueue(path);
|
||||
_view.UpdateMRUMenu(MostRecentUsedFiles);
|
||||
}
|
||||
|
||||
if (!_repository.LoadContacts(path))
|
||||
_view.DisplayMessage("File seems missing or corrupted!", "Error");
|
||||
else
|
||||
_view.DisplayContacts(_repository.Contacts);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ChangeContactSelectedHandler(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -32,4 +32,4 @@ using System.Runtime.InteropServices;
|
||||
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
|
||||
// en utilisant '*', comme indiqué ci-dessous :
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.5.7")]
|
||||
[assembly: AssemblyVersion("0.5.8")]
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
0.5.5
|
||||
0.5.8
|
||||
Merged PR #42, #45
|
||||
|
||||
0.5.7
|
||||
added a feature to batch export/clear/count images.
|
||||
Fix bug when opening files by menu.
|
||||
some buttons click were not working properly.
|
||||
|
||||
0.5.6
|
||||
Not released!
|
||||
|
||||
0.5.5
|
||||
redisgn the extra tab
|
||||
Fix some bugs
|
||||
|
||||
@@ -31,4 +42,4 @@
|
||||
Replaced Moq with nsubstitute (Test mocking library).
|
||||
|
||||
0.1
|
||||
Intial release
|
||||
Intial release
|
||||
|
||||
@@ -48,18 +48,39 @@ namespace VCFEditor.Repository
|
||||
_fileHandler = fileHandler;
|
||||
}
|
||||
|
||||
public bool LoadMultipleFilesContact(string path)
|
||||
{
|
||||
Contacts.Clear();
|
||||
|
||||
string[] filePaths = _fileHandler.GetFiles(path, "*.vcf");
|
||||
if (filePaths.Count() == 0)
|
||||
return false;
|
||||
|
||||
foreach (var item in filePaths)
|
||||
{
|
||||
var result = LoadContactFromFile(item);
|
||||
Contacts.AddRange(result);
|
||||
OriginalContactList = Contacts;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool LoadContacts(string fileName)
|
||||
{
|
||||
Contacts.Clear();
|
||||
|
||||
this.fileName = fileName;
|
||||
Contacts = LoadContactFromFile(fileName);
|
||||
OriginalContactList = Contacts;
|
||||
return true;
|
||||
}
|
||||
|
||||
public SortableBindingList<Contact> LoadContactFromFile(string fileName)
|
||||
{
|
||||
if (!_fileHandler.FileExist(fileName))
|
||||
{
|
||||
OriginalContactList = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
SortableBindingList<Contact> ListOfContacts = new SortableBindingList<Contact>();
|
||||
|
||||
string[] lines = _fileHandler.ReadAllLines(fileName);
|
||||
|
||||
StringBuilder RawContent = new StringBuilder();
|
||||
@@ -72,26 +93,19 @@ namespace VCFEditor.Repository
|
||||
{
|
||||
if (string.Equals(lines[i].TrimEnd(), "END:VCARD", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
contact = new Contact
|
||||
{
|
||||
card = ParseRawContent(RawContent)
|
||||
};
|
||||
|
||||
Contacts.Add(contact);
|
||||
contact = new Contact(ParseRawContent(RawContent));
|
||||
ListOfContacts.Add(contact);
|
||||
RawContent.Length = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
OriginalContactList = null;
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
OriginalContactList = Contacts;
|
||||
return true;
|
||||
}
|
||||
|
||||
return ListOfContacts;
|
||||
}
|
||||
private vCard ParseRawContent(StringBuilder rawContent)
|
||||
{
|
||||
vCard card = null;
|
||||
@@ -104,11 +118,9 @@ namespace VCFEditor.Repository
|
||||
|
||||
public void AddEmptyContact()
|
||||
{
|
||||
if (_contacts != null && _contacts.Count > 0)
|
||||
{
|
||||
Contact contact = new Contact();
|
||||
Contacts.Add(contact);
|
||||
}
|
||||
Contact contact = new Contact();
|
||||
contact.isDirty = true;
|
||||
Contacts.Add(contact);
|
||||
}
|
||||
|
||||
public void SaveContactsToFile(string fileName)
|
||||
@@ -392,8 +404,47 @@ namespace VCFEditor.Repository
|
||||
|
||||
public string GenerateFileName(string fileName, int index, string extension)
|
||||
{
|
||||
string result = Path.Combine(Path.GetDirectoryName(fileName), index.ToString() + "." + extension);
|
||||
string result = _fileHandler.GetFileNameWithExtension(fileName, index, extension);
|
||||
return result;
|
||||
}
|
||||
|
||||
public int SaveSplittedFiles(string FolderPath)
|
||||
{
|
||||
//Do not save the deleted ones!
|
||||
var contactsToSave = Contacts.Where(x => !x.isDeleted).ToList();
|
||||
int count;
|
||||
for (count = 0; count < contactsToSave.Count(); count++)
|
||||
{
|
||||
var entry = contactsToSave[count];
|
||||
string SerializedCard = GenerateStringFromVCard(entry.card);
|
||||
|
||||
//Check if filename for the card is empty, and generate one if empty
|
||||
if (string.IsNullOrEmpty(entry.path))
|
||||
entry.path = GenerateFileName(FolderPath, entry.FamilyName, count);
|
||||
|
||||
_fileHandler.WriteAllText(entry.path, SerializedCard);
|
||||
|
||||
//Clean the flag for every contact, even the deleted ones.
|
||||
entry.isDirty = false;
|
||||
|
||||
}
|
||||
|
||||
//Clean the global flag for the entire vCard Catalog.
|
||||
_dirty = false;
|
||||
|
||||
//return number of contacts processed!
|
||||
return count;
|
||||
}
|
||||
|
||||
private string GenerateFileName(string FolderPath, string familyName, int index)
|
||||
{
|
||||
string FinalPath;
|
||||
if (string.IsNullOrEmpty(familyName))
|
||||
FinalPath = _fileHandler.GetVcfFileName(FolderPath, index.ToString());
|
||||
else
|
||||
FinalPath = _fileHandler.GetVcfFileName(FolderPath, familyName);
|
||||
|
||||
return FinalPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ namespace vCardEditor.Repository
|
||||
|
||||
public void MoveFile(string newFilename, string oldFilename)
|
||||
{
|
||||
File.Move(newFilename, oldFilename);
|
||||
if (File.Exists(newFilename))
|
||||
File.Move(newFilename, oldFilename);
|
||||
|
||||
}
|
||||
|
||||
public string[] ReadAllLines(string filename)
|
||||
@@ -43,5 +45,22 @@ namespace vCardEditor.Repository
|
||||
ms.WriteTo(fs);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetVcfFileName(string folderPath, string filename)
|
||||
{
|
||||
return Path.Combine(folderPath, filename + ".vcf");
|
||||
}
|
||||
|
||||
public string GetFileNameWithExtension(string fileName, int index, string extension)
|
||||
{
|
||||
return Path.Combine(Path.GetDirectoryName(fileName), index.ToString() + "." + extension);
|
||||
}
|
||||
|
||||
public string[] GetFiles(string path, string ext)
|
||||
{
|
||||
string[] filePaths = Directory.GetFiles(path, ext,SearchOption.TopDirectoryOnly);
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Thought.vCards;
|
||||
using VCFEditor.Model;
|
||||
using System.ComponentModel;
|
||||
using vCardEditor.View;
|
||||
|
||||
namespace VCFEditor.Repository
|
||||
@@ -15,6 +11,7 @@ namespace VCFEditor.Repository
|
||||
string fileName { get; set; }
|
||||
SortableBindingList<Contact> Contacts { get; set; }
|
||||
bool LoadContacts(string fileName);
|
||||
bool LoadMultipleFilesContact(string path);
|
||||
SortableBindingList<Contact> FilterContacts(string p);
|
||||
void SaveContactsToFile(string fileName);
|
||||
void DeleteContact();
|
||||
@@ -28,5 +25,7 @@ namespace VCFEditor.Repository
|
||||
|
||||
string GenerateStringFromVCard(vCard card);
|
||||
string GenerateFileName(string fileName, int index, string extension);
|
||||
int SaveSplittedFiles(string Path);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace vCardEditor.Repository
|
||||
using System.IO;
|
||||
|
||||
namespace vCardEditor.Repository
|
||||
{
|
||||
public interface IFileHandler
|
||||
{
|
||||
@@ -9,5 +11,8 @@
|
||||
string GetExtension(string path);
|
||||
string ChangeExtension(string path, string extension);
|
||||
void WriteBytesToFile(string imageFile, byte[] image);
|
||||
string GetVcfFileName(string folderPath, string familyName);
|
||||
string GetFileNameWithExtension(string fileName, int index, string extension);
|
||||
string[] GetFiles(string path, string ext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace vCardEditor.View.Customs
|
||||
miHome.Tag = new vCardPhone(string.Empty, vCardPhoneTypes.Home);
|
||||
miHome.Click += MenuItemClickHandlers;
|
||||
|
||||
miWork.Tag = new vCardPhone(string.Empty, vCardPhoneTypes.Home);
|
||||
miWork.Tag = new vCardPhone(string.Empty, vCardPhoneTypes.Work);
|
||||
miWork.Click += MenuItemClickHandlers;
|
||||
|
||||
miEmail.Tag = new vCardEmailAddress(string.Empty, vCardEmailAddressType.Internet);
|
||||
|
||||
@@ -30,13 +30,15 @@ namespace VCFEditor.View
|
||||
event EventHandler CountImagesEvent;
|
||||
event EventHandler ClearImagesEvent;
|
||||
event EventHandler BatchExportImagesEvent;
|
||||
event EventHandler<EventArg<string>> OpenFolderEvent;
|
||||
event EventHandler SplitFileEvent;
|
||||
int SelectedContactIndex { get; }
|
||||
void DisplayContacts(SortableBindingList<Contact> contacts);
|
||||
void DisplayContactDetail(vCard card, string FileName);
|
||||
void ClearContactDetail();
|
||||
bool AskMessage(string msg, string caption);
|
||||
void DisplayMessage(string msg, string caption);
|
||||
string DisplayOpenDialog(string filter);
|
||||
string DisplayOpenFileDialog(string filter);
|
||||
string DisplaySaveDialog(string filename);
|
||||
void UpdateMRUMenu(FixedList MRUList);
|
||||
|
||||
@@ -48,5 +50,6 @@ namespace VCFEditor.View
|
||||
void DisplayQRCode(string content);
|
||||
|
||||
void ClearImageFromForm();
|
||||
string DisplayOpenFolderDialog();
|
||||
}
|
||||
}
|
||||
|
||||
64
vCardEditor/View/MainForm.Designer.cs
generated
64
vCardEditor/View/MainForm.Designer.cs
generated
@@ -32,7 +32,7 @@ namespace vCardEditor.View
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.miSave = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@@ -56,8 +56,8 @@ namespace vCardEditor.View
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
|
||||
this.tbsNew = new System.Windows.Forms.ToolStripButton();
|
||||
this.tbsOpen = new System.Windows.Forms.ToolStripButton();
|
||||
this.tbsSave = new System.Windows.Forms.ToolStripButton();
|
||||
this.tbsOpen = new System.Windows.Forms.ToolStripSplitButton();
|
||||
this.openFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.tbsDelete = new System.Windows.Forms.ToolStripButton();
|
||||
this.tbsQR = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
@@ -104,6 +104,8 @@ namespace vCardEditor.View
|
||||
this.menuExtraField = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.miNote = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.miOrg = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.tbsSave = new System.Windows.Forms.ToolStripSplitButton();
|
||||
this.splitToFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.toolStrip1.SuspendLayout();
|
||||
this.gbNameList.SuspendLayout();
|
||||
@@ -248,27 +250,27 @@ namespace vCardEditor.View
|
||||
this.clearToolStripMenuItem,
|
||||
this.countToolStripMenuItem});
|
||||
this.imagesToolStripMenuItem.Name = "imagesToolStripMenuItem";
|
||||
this.imagesToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.imagesToolStripMenuItem.Size = new System.Drawing.Size(140, 26);
|
||||
this.imagesToolStripMenuItem.Text = "Images";
|
||||
//
|
||||
// exportToolStripMenuItem
|
||||
//
|
||||
this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
|
||||
this.exportToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.exportToolStripMenuItem.Size = new System.Drawing.Size(135, 26);
|
||||
this.exportToolStripMenuItem.Text = "Export";
|
||||
this.exportToolStripMenuItem.Click += new System.EventHandler(this.exportToolStripMenuItem_Click);
|
||||
//
|
||||
// clearToolStripMenuItem
|
||||
//
|
||||
this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
|
||||
this.clearToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.clearToolStripMenuItem.Size = new System.Drawing.Size(135, 26);
|
||||
this.clearToolStripMenuItem.Text = "Clear";
|
||||
this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click);
|
||||
//
|
||||
// countToolStripMenuItem
|
||||
//
|
||||
this.countToolStripMenuItem.Name = "countToolStripMenuItem";
|
||||
this.countToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.countToolStripMenuItem.Size = new System.Drawing.Size(135, 26);
|
||||
this.countToolStripMenuItem.Text = "Count";
|
||||
this.countToolStripMenuItem.Click += new System.EventHandler(this.countToolStripMenuItem_Click);
|
||||
//
|
||||
@@ -330,22 +332,21 @@ namespace vCardEditor.View
|
||||
// tbsOpen
|
||||
//
|
||||
this.tbsOpen.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.tbsOpen.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.openFolderToolStripMenuItem});
|
||||
this.tbsOpen.Image = ((System.Drawing.Image)(resources.GetObject("tbsOpen.Image")));
|
||||
this.tbsOpen.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.tbsOpen.Name = "tbsOpen";
|
||||
this.tbsOpen.Size = new System.Drawing.Size(29, 24);
|
||||
this.tbsOpen.Size = new System.Drawing.Size(39, 24);
|
||||
this.tbsOpen.Text = "&Open";
|
||||
this.tbsOpen.Click += new System.EventHandler(this.tbsOpen_Click);
|
||||
this.tbsOpen.ButtonClick += new System.EventHandler(this.tbsOpen_Click);
|
||||
//
|
||||
// tbsSave
|
||||
// openFolderToolStripMenuItem
|
||||
//
|
||||
this.tbsSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.tbsSave.Image = ((System.Drawing.Image)(resources.GetObject("tbsSave.Image")));
|
||||
this.tbsSave.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.tbsSave.Name = "tbsSave";
|
||||
this.tbsSave.Size = new System.Drawing.Size(29, 24);
|
||||
this.tbsSave.Text = "&Save";
|
||||
this.tbsSave.Click += new System.EventHandler(this.tbsSave_Click);
|
||||
this.openFolderToolStripMenuItem.Name = "openFolderToolStripMenuItem";
|
||||
this.openFolderToolStripMenuItem.Size = new System.Drawing.Size(174, 26);
|
||||
this.openFolderToolStripMenuItem.Text = "Open Folder";
|
||||
this.openFolderToolStripMenuItem.Click += new System.EventHandler(this.openFolderToolStripMenuItem_Click);
|
||||
//
|
||||
// tbsDelete
|
||||
//
|
||||
@@ -412,8 +413,8 @@ namespace vCardEditor.View
|
||||
this.dgContacts.AllowUserToAddRows = false;
|
||||
this.dgContacts.AllowUserToDeleteRows = false;
|
||||
this.dgContacts.AllowUserToResizeRows = false;
|
||||
dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
|
||||
this.dgContacts.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
|
||||
dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
|
||||
this.dgContacts.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle2;
|
||||
this.dgContacts.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
@@ -861,6 +862,25 @@ namespace vCardEditor.View
|
||||
this.miOrg.Text = "Organisation";
|
||||
this.miOrg.Click += new System.EventHandler(this.miOrg_Click);
|
||||
//
|
||||
// tbsSave
|
||||
//
|
||||
this.tbsSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.tbsSave.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.splitToFilesToolStripMenuItem});
|
||||
this.tbsSave.Image = ((System.Drawing.Image)(resources.GetObject("tbsSave.Image")));
|
||||
this.tbsSave.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.tbsSave.Name = "tbsSave";
|
||||
this.tbsSave.Size = new System.Drawing.Size(39, 24);
|
||||
this.tbsSave.Text = "&Save";
|
||||
this.tbsSave.ButtonClick += new System.EventHandler(this.tbsSave_Click);
|
||||
//
|
||||
// splitToFilesToolStripMenuItem
|
||||
//
|
||||
this.splitToFilesToolStripMenuItem.Name = "splitToFilesToolStripMenuItem";
|
||||
this.splitToFilesToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.splitToFilesToolStripMenuItem.Text = "Split to files";
|
||||
this.splitToFilesToolStripMenuItem.Click += new System.EventHandler(this.splitToFilesToolStripMenuItem_Click);
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AllowDrop = true;
|
||||
@@ -919,8 +939,6 @@ namespace vCardEditor.View
|
||||
private System.Windows.Forms.ToolStripMenuItem miAbout;
|
||||
private System.Windows.Forms.StatusStrip statusStrip1;
|
||||
private System.Windows.Forms.ToolStrip toolStrip1;
|
||||
private System.Windows.Forms.ToolStripButton tbsOpen;
|
||||
private System.Windows.Forms.ToolStripButton tbsSave;
|
||||
private System.Windows.Forms.ToolStripButton tbsDelete;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
private System.Windows.Forms.ToolStripButton tbsAbout;
|
||||
@@ -981,5 +999,9 @@ namespace vCardEditor.View
|
||||
private System.Windows.Forms.ToolStripMenuItem miOrg;
|
||||
private ExtendedPanel extendedPanelWeb;
|
||||
private ExtendedPanel extendedPanelPhones;
|
||||
private System.Windows.Forms.ToolStripSplitButton tbsOpen;
|
||||
private System.Windows.Forms.ToolStripMenuItem openFolderToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripSplitButton tbsSave;
|
||||
private System.Windows.Forms.ToolStripMenuItem splitToFilesToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
@@ -37,9 +37,12 @@ namespace vCardEditor.View
|
||||
public event EventHandler CountImagesEvent;
|
||||
public event EventHandler ClearImagesEvent;
|
||||
public event EventHandler BatchExportImagesEvent;
|
||||
public event EventHandler<EventArg<string>> OpenFolderEvent;
|
||||
public event EventHandler SplitFileEvent;
|
||||
|
||||
|
||||
|
||||
|
||||
ComponentResourceManager resources;
|
||||
|
||||
private int LastRowIndex = -1;
|
||||
@@ -92,6 +95,7 @@ namespace vCardEditor.View
|
||||
|
||||
public void DisplayContacts(SortableBindingList<Contact> contacts)
|
||||
{
|
||||
bsContacts.DataSource = null;
|
||||
if (contacts != null)
|
||||
bsContacts.DataSource = contacts;
|
||||
|
||||
@@ -99,6 +103,9 @@ namespace vCardEditor.View
|
||||
|
||||
private void tbsSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dgContacts.RowCount == 0)
|
||||
return;
|
||||
|
||||
if (SaveContactsSelected != null)
|
||||
{
|
||||
//make sure the last changes in the textboxes is saved.
|
||||
@@ -413,6 +420,7 @@ namespace vCardEditor.View
|
||||
|
||||
private void BuildMRUMenu()
|
||||
{
|
||||
//TODO: Open File or Folder.
|
||||
recentFilesMenuItem.DropDownItemClicked += (s, e) => OpenFile(s, e.ClickedItem.Text);
|
||||
UpdateMRUMenu(ConfigRepository.Instance.Paths);
|
||||
|
||||
@@ -459,7 +467,7 @@ namespace vCardEditor.View
|
||||
{
|
||||
MessageBox.Show(msg, caption);
|
||||
}
|
||||
public string DisplayOpenDialog(string filter = "")
|
||||
public string DisplayOpenFileDialog(string filter = "")
|
||||
{
|
||||
string filename = string.Empty;
|
||||
openFileDialog.Filter = filter;
|
||||
@@ -489,7 +497,7 @@ namespace vCardEditor.View
|
||||
{
|
||||
if (ModifyImage != null)
|
||||
{
|
||||
var fileName = DisplayOpenDialog();
|
||||
var fileName = DisplayOpenFileDialog();
|
||||
if (!string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
try
|
||||
@@ -703,5 +711,26 @@ namespace vCardEditor.View
|
||||
{
|
||||
BatchExportImagesEvent?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
private void openFolderToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var evt = new EventArg<string>(string.Empty);
|
||||
OpenFolderEvent?.Invoke(sender, evt);
|
||||
}
|
||||
|
||||
private void splitToFilesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
SplitFileEvent?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
public string DisplayOpenFolderDialog()
|
||||
{
|
||||
string result = string.Empty;
|
||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
result = dialog.SelectedPath;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,5 +95,36 @@ namespace vCardEditor.View
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/43331145/how-can-i-improve-performance-of-an-addrange-method-on-a-custom-bindinglist
|
||||
public void AddRange(IEnumerable<T> collection)
|
||||
{
|
||||
if (collection == null)
|
||||
throw new ArgumentNullException(nameof(collection));
|
||||
|
||||
// Remember the current setting for RaiseListChangedEvents
|
||||
// (if it was already deactivated, we shouldn't activate it after adding!).
|
||||
var oldRaiseEventsValue = RaiseListChangedEvents;
|
||||
|
||||
try
|
||||
{
|
||||
RaiseListChangedEvents = false;
|
||||
|
||||
foreach (var value in collection)
|
||||
Add(value);
|
||||
}
|
||||
// Restore the old setting for RaiseListChangedEvents (even if there was an exception),
|
||||
// and fire the ListChanged-event once (if RaiseListChangedEvents is activated).
|
||||
finally
|
||||
{
|
||||
RaiseListChangedEvents = oldRaiseEventsValue;
|
||||
|
||||
if (RaiseListChangedEvents)
|
||||
ResetBindings();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +178,7 @@ namespace vCardEditor_Test
|
||||
|
||||
repo.AddEmptyContact();
|
||||
|
||||
|
||||
Assert.IsTrue(repo.Contacts.Count == 0);
|
||||
Assert.IsTrue(repo.Contacts.Count == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +259,42 @@ namespace vCardEditor_Test
|
||||
Assert.IsTrue(repo.Contacts[0].isDirty);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AddContact_ShouldCreateEmtptyContactFile_Test()
|
||||
{
|
||||
|
||||
var fileHandler = Substitute.For<IFileHandler>();
|
||||
var repo = Substitute.For<ContactRepository>(fileHandler);
|
||||
var view = Substitute.For<IMainView>();
|
||||
_ = new MainPresenter(view, repo);
|
||||
view.AddContact += Raise.Event();
|
||||
|
||||
view.Received().DisplayContacts(Arg.Any<SortableBindingList<Contact>>());
|
||||
Assert.IsTrue(repo.Contacts.Count == 1);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SaveSplittedFile_ShouldCall3TimesFileSaving_Test()
|
||||
{
|
||||
|
||||
var fileHandler = Substitute.For<IFileHandler>();
|
||||
fileHandler.ReadAllLines(Arg.Any<string>()).Returns(Entries.vcfFourEntry);
|
||||
fileHandler.FileExist(Arg.Any<string>()).Returns(true);
|
||||
|
||||
var repo = Substitute.For<ContactRepository>(fileHandler);
|
||||
|
||||
repo.LoadContacts("aaa.vcf");
|
||||
repo.Contacts[3].isDeleted = true;
|
||||
|
||||
var view = Substitute.For<IMainView>();
|
||||
view.DisplayOpenFolderDialog().Returns("aaa");
|
||||
_ = new MainPresenter(view, repo);
|
||||
view.SplitFileEvent += Raise.Event();
|
||||
|
||||
//Should save only 3 files.
|
||||
fileHandler.Received(3).WriteAllText(Arg.Any<string>(), Arg.Any<string>());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user