63 Commits

Author SHA1 Message Date
Abdel
05d6580ba6 Merge pull request #56 from JDM170/fixes
Update
2025-06-18 13:47:15 -04:00
a60ae3c5a2 Update
* Updated DisplaySaveDialog
* Fixed a bug in SaveContactsHandler, when an exception was thrown when canceling file saving
* The window title displays "New file" instead of empty when creating a new file
* Commented out the code that saves a website with the "work" type (the program does not work with this type of website)
* Explicitly specified data types for some variables
* Minor code formatting

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-06-18 20:45:44 +07:00
abdelkader
9c66157599 fixed test 2025-06-12 13:28:37 -04:00
Abdel
a67e88bb22 Merge pull request #53 from JDM170/update_readme
Update README
2025-06-10 13:23:33 -04:00
7d029293b0 Update README.md
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-06-05 17:39:00 +07:00
abdelkader
c9b324a8c6 Merge branch 'master' of https://github.com/abdelkader/vCardEditor 2025-06-04 22:29:47 -04:00
Abdel
8457b57dae Merge pull request #52 from JDM170/fix_dialogs
Dialog fixes
2025-06-04 22:28:50 -04:00
Abdel
1b4d8373f2 Merge pull request #51 from JDM170/code_fixes
Corrections and additions in code
2025-06-04 22:27:54 -04:00
abdelkader
9c562b3f7e added test 2025-06-04 22:19:22 -04:00
a37ceee7f2 Update
* Aligning buttons on the About dialog and removing an extra line in tableLayoutPanel
* Removed unnecessary cancel button

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-06-04 18:41:58 +07:00
8392f0c273 Update
* Added question when deleting data from the Extras tab
* ReplaceControls function merged with RemoveControl in ExtendedPanel
* Fixed strange logic of working with AskMessage
* Removed extra lines and spaces (again:D)

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-06-04 17:16:26 +07:00
abdelkader
76398ae2c4 Added test and refactored the localization 2025-06-03 22:09:37 -04:00
abdelkader
dc47c59dc9 i18n draft 2025-06-02 21:37:39 -04:00
Abdel
1272d93ae9 Merge pull request #50 from JDM170/delete_bug_2
Fixed bug when deleting a number or site was not saved (separate signal)
2025-06-02 15:19:58 -04:00
892bf14a25 Fixed bug when deleting a number or site was not saved (separate signal)
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-05-31 20:26:43 +07:00
abdelkader
0f8a6387e9 Merge branch 'master' of https://github.com/abdelkader/vCardEditor 2025-05-30 14:24:15 -04:00
abdelkader
313d70ae05 fixed merge 2025-05-30 14:23:51 -04:00
Abdel
5d8fd20541 Merge pull request #46 from JDM170/issue_40
Added a dialog box with a question about deleting contacts
2025-05-30 14:17:58 -04:00
26dfe4c357 Update
* Fixed indents, removed extra lines and spaces
* Partially removed var statement declaration (proper variable declaration)
* Sorted and removed unnecessary usings
* Correction of typos

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-05-31 00:09:41 +07:00
75f6c55cbc Added a dialog box with a question about deleting contacts
Closes abdelkader/vCardEditor#40

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-05-30 12:15:40 +07:00
abdelkader
a7c66075a1 changed version number 2025-05-29 08:51:27 -04:00
Abdel
c4a29b678f Merge pull request #45 from JDM170/fix_indexoutofrange_exception
Fixed IndexOutOfRange exception when trying to search
2025-05-29 08:47:20 -04:00
14efe79576 Fixed IndexOutOfRange exception when trying to search
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
2025-05-29 10:37:40 +07:00
Abdel
66a77f3b98 Merge pull request #42 from JDM170/fix_work_number
Fixed adding a work number via extended panel
2025-05-28 15:12:09 -04:00
5f33b3adaf fixed adding a work number via extended panel 2024-07-30 15:22:20 +07:00
abdelkader
90dce429bd bug fixed 2024-04-04 12:45:14 -04:00
abdelkader
b17fce8dde 2nd draft for loading folder 2024-04-04 12:42:08 -04:00
abdelkader
afe52e2b18 draft for opening multiple vcard files 2024-04-02 22:45:32 -04:00
abdelkader
c89d9a197c fixed bug 2024-04-02 13:14:58 -04:00
abdelkader
6b57814c5b added a test for SaveSplittedFile 2024-04-02 12:45:31 -04:00
abdelkader
2023043889 draft for saving split files 2024-04-02 12:31:33 -04:00
abdelkader
4401f13fb4 allow to create a empty vcard file 2024-03-30 19:12:35 -04:00
Abdel
c9b9dfb623 Update Releases.txt 2024-03-28 18:53:42 -04:00
Abdel
d79ea44306 Update README.md 2024-03-28 18:46:21 -04:00
abdelkader
724113e304 added image batch export 2024-03-28 18:39:06 -04:00
abdelkader
32bf064f93 added the clear image batch operation 2024-03-28 13:14:43 -04:00
abdelkader
250279cf7c fix when opening new file
feature: image count
2024-03-28 12:10:40 -04:00
abdelkader
62744daa8a fix image type retrieval 2024-03-27 17:22:17 -04:00
abdelkader
4dad2c4151 fix the filter 2024-03-21 08:57:48 -04:00
abdelkader
e89b85411f Fixed the image handlers 2024-03-21 08:47:22 -04:00
abdelkader
81ce797614 keep focus on text box filter 2024-03-21 08:41:38 -04:00
abdelkader
2eb633cfd7 remove unused warning
fix bug
2024-03-21 08:39:29 -04:00
abdelkader
7a575bf526 forget a declaration 2024-03-20 18:17:39 -04:00
abdelkader
ad990213be Fix a multiple firing event 2024-03-20 18:16:55 -04:00
abdelkader
d1296f66b7 show the last inserted address 2024-03-20 17:21:05 -04:00
abdelkader
6b133c27f5 Merge branch 'master' of https://github.com/abdelkader/vCardEditor 2024-03-20 16:04:50 -04:00
abdelkader
ce69d72d46 fix a bug in Add Address 2024-03-20 16:04:28 -04:00
abdelkader
b2edc48f66 Added Parcel, and Preferred 2024-03-20 15:04:18 -04:00
abdelkader
ae3961ec33 rename OverWrite
refactor some code
2024-03-20 09:54:14 -04:00
abdelkader
bad8fee66b arrange some code 2024-03-20 09:50:48 -04:00
abdelkader
4ab38ffea7 move some code around. 2024-03-20 09:48:28 -04:00
abdelkader
2faa7965cd Extra Tab show number of item.
Correct a designer pb
2024-03-20 09:34:17 -04:00
Abdel
3d558b0216 Update README.md
new image
2024-03-19 13:09:52 -04:00
Abdel
ad28a57df8 Update README.md
added a new image
2024-03-19 13:05:34 -04:00
abdelkader
ba9d26f981 some minor changes 2024-03-19 12:28:25 -04:00
abdelkader
abbb03dddf added a button to the extra tab 2024-03-19 12:04:55 -04:00
abdelkader
a989351889 remove the flowlayout panel, and replace it with a simple panel. 2024-03-19 11:48:18 -04:00
abdelkader
22f7f88018 move the declaration, so the autogenerate of vs won't remove them 2024-03-19 11:41:37 -04:00
abdelkader
85bb588f42 saving only if change occured 2024-03-19 08:41:19 -04:00
abdelkader
1bf467f81f catch error when parsing error.
optimize parsing of vcard
save last row
2024-03-18 17:26:20 -04:00
abdelkader
7e8c43e011 refactor 2024-03-18 13:02:42 -04:00
abdelkader
7d09a9ee3e Use Version Class to handle version, and added some error handling 2024-03-18 12:34:47 -04:00
abdelkader
77c1e45bfd the application check if un update is available. 2024-03-18 11:05:52 -04:00
102 changed files with 1929 additions and 1026 deletions

View File

@@ -1,30 +1,23 @@
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B2KV8WP)
<a href="https://github.com/abdelkader/vCardEditor/releases/latest/download/vCardEditor.exe"><img src="https://camo.githubusercontent.com/d83fa798b621f1e112646fcc4aa74fff1ff6a8b22f5fc1da5ed8f79ddb4a51cb/68747470733a2f2f62616467656e2e6e65742f6769746875622f72656c656173652f4e61657265656e2f5374726170646f776e2e6a73" alt="Latest release" data-canonical-src="https://badgen.net/github/release/Naereen/Strapdown.js" style="max-width: 100%;"></a>
<a href="https://github.com/abdelkader/vCardEditor/releases/latest/download/vCardEditor.exe"><img src="https://badgen.net/github/release/Naereen/Strapdown.js" alt="Latest release" style="max-width: 100%;"></a>
## vCard Editor
A Simple vcf file Editor. You can export easily edit (modify, delete) entries of a vcf file with this simple tool.
The software is still in **early stage**.
<p align="center"><img src="https://user-images.githubusercontent.com/169070/236289228-106c1489-e01d-400c-968e-92d3e2be74ab.png" width="800"></p>
## ✅ Features
- [x] No need to install anything. Just head to the release section and download the last release version.
- [x] Add/Export images
## 📚 Tech Stack
- 🧰 [Wonderful library of parsing and generating vcf format](https://github.com/drlongnecker/Thought.vCards)
- 📖 [MVP pattern from this example](https://github.com/lennykean/NoteCards)
- 🧰 [SortableBindingList](http://timvw.be/2008/08/02/presenting-the-sortablebindinglistt-take-two/)
- 🧰 [Custom TabControl](https://github.com/r-aghaei/TabControlWithCloseButtonAndAddButton)
- 🧰 [QRCoder](https://github.com/codebude/QRCoder)
- 🧰 [Wonderful library of parsing and generating vcf format](https://github.com/drlongnecker/Thought.vCards)
- 📖 [MVP pattern from this example](https://github.com/lennykean/NoteCards)
- 🧰 [SortableBindingList](http://timvw.be/2008/08/02/presenting-the-sortablebindinglistt-take-two/)
- 🧰 [Custom TabControl](https://github.com/r-aghaei/TabControlWithCloseButtonAndAddButton)
- 🧰 [QRCoder](https://github.com/codebude/QRCoder)
## 📑 Release notes
Check release text file for history.
@@ -32,8 +25,4 @@ Check release text file for history.
## 👷 Contributing and help
Contributions are always welcome! Check ths projet or ths issue page for ideas.
- 📝 [**Report a bug**](https://github.com/abdelkader/vCardEditor/issues)
- 🙋‍♀️ [**Request a feature**](https://github.com/abdelkader/vCardEditor/discussions)
- 🙋‍ [**Request a feature**](https://github.com/abdelkader/vCardEditor/discussions)

View File

@@ -0,0 +1,22 @@
using System.Collections.Generic;
namespace vCardEditor
{
public interface ILocalizationProvider
{
string this[string key] { get; }
void SetLanguage(string langCode);
string CurrentLanguage { get; }
IReadOnlyDictionary<string, string> CurrentMessages { get; }
IEnumerable<string> AvailableLanguages { get; }
IEnumerable<string> AvailableLanguageNames { get; }
}
}

View File

@@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Linq;
using vCardEditor.Libs.TinyJson;
namespace vCardEditor
{
public class JsonLocalizationProvider : ILocalizationProvider
{
private readonly LocalizationFile _localization;
private string _currentLanguage;
public JsonLocalizationProvider(LocalizationFile localization, string defaultLanguage = "en")
{
_localization = localization;
_currentLanguage = defaultLanguage;
}
public void SetLanguage(string langCode)
{
if (_localization.languages.ContainsKey(langCode))
_currentLanguage = langCode;
}
public string this[string key]
{
get
{
if (_localization.languages.TryGetValue(_currentLanguage, out LanguageData lang))
{
if (lang.messages.TryGetValue(key, out string value))
return value;
}
if (_localization.languages.TryGetValue("en", out LanguageData fallbackLang))
{
if (fallbackLang.messages.TryGetValue(key, out string fallbackMsg))
return fallbackMsg;
}
return $"!{key}!";
}
}
public IReadOnlyDictionary<string, string> CurrentMessages =>
_localization.languages.TryGetValue(_currentLanguage, out LanguageData lang)
? lang.messages
: new Dictionary<string, string>();
public IEnumerable<string> AvailableLanguages => _localization.languages.Keys;
public IEnumerable<string> AvailableLanguageNames => _localization.languages?.Values != null
? _localization.languages.Values.Select(l => l?.name).Where(n => !string.IsNullOrEmpty(n))
: new List<string>();
public string CurrentLanguage => _currentLanguage;
}
}

View File

@@ -1906,13 +1906,12 @@ namespace Thought.vCards
/// </summary>
private void ReadInto_PHOTO(vCard card, vCardProperty property)
{
string[] Formats = { "GIF", "CGM", "WMF", "JPEG", "BMP", "MET", "PMB", "DIB", "PICT", "TIFF", "PS", "PDF" };
string imageType = property.Subproperties.GetValue("TYPE", Formats);
string imageType = property.Subproperties.GetValue("TYPE");
// The PHOTO property contains an embedded (encoded) image
// or a link to an image. A URL (linked) image is supposed
// to be indicated with the VALUE=URI subproperty.
string valueType = property.Subproperties.GetValue("VALUE");
//URI is the standard, but I've seen examples online of URL
@@ -2290,10 +2289,7 @@ namespace Thought.vCards
firstLine = firstLine.Trim();
if (firstLine.Length == 0)
{
Warnings.Add(Thought.vCards.WarningMessages.BlankLine);
continue;
}
// Get the index of the colon (:) in this
// property line. All vCard properties are
@@ -2301,10 +2297,7 @@ namespace Thought.vCards
int colonIndex = firstLine.IndexOf(':');
if (colonIndex == -1)
{
Warnings.Add(Thought.vCards.WarningMessages.ColonMissing);
continue;
}
// Get the name portion of the property. This
// portion contains the property name as well
@@ -2312,10 +2305,7 @@ namespace Thought.vCards
string namePart = firstLine.Substring(0, colonIndex).Trim();
if (string.IsNullOrEmpty(namePart))
{
Warnings.Add(Thought.vCards.WarningMessages.EmptyName);
continue;
}
// Split apart the name portion of the property.
// A property can have subproperties, separated
@@ -2323,17 +2313,14 @@ namespace Thought.vCards
string[] nameParts = namePart.Split(';');
for (int i = 0; i < nameParts.Length; i++)
nameParts[i] = nameParts[i].Trim();
nameParts[i] = nameParts[i].Trim();
// The name of the property is supposed to
// be first on the line. An empty name is not
// legal syntax.
if (nameParts[0].Length == 0)
{
Warnings.Add(Thought.vCards.WarningMessages.EmptyName);
continue;
}
// At this point there is sufficient text
// to define a vCard property. The only
@@ -2362,13 +2349,14 @@ namespace Thought.vCards
if (subNameValue.Length == 1)
{
// The Split function above returned a single
// array element. This means no equal (=) sign
// was present. The subproperty consists of
// a name only.
property.Subproperties.Add(
nameParts[index].Trim());
// The Split function above returned a single
// array element. This means no equal (=) sign
// was present. The subproperty consists of
// a name only.
if (!string.IsNullOrEmpty(subNameValue[0]))
{
property.Subproperties.Add(nameParts[index].Trim());
}
}
else
{

View File

@@ -311,8 +311,8 @@ namespace Thought.vCards
vCardValueCollection values = new vCardValueCollection(';');
values.Add(string.Empty);
values.Add(string.Empty);
values.Add(address.PostOfficeBox);
values.Add(address.ExtendedAddress);
values.Add(!string.IsNullOrEmpty(address.Street) ? address.Street.Replace("\r\n", "\n") : string.Empty);
values.Add(address.City);
values.Add(address.Region);

View File

@@ -0,0 +1,7 @@
namespace vCardEditor.Libs.TinyJson
{
public interface IParser
{
T Deserialize<T>(string json);
}
}

View File

@@ -0,0 +1,377 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
namespace TinyJson
{
// Really simple JSON parser in ~300 lines
// - Attempts to parse JSON files with minimal GC allocation
// - Nice and simple "[1,2,3]".FromJson<List<int>>() API
// - Classes and structs can be parsed too!
// class Foo { public int Value; }
// "{\"Value\":10}".FromJson<Foo>()
// - Can parse JSON without type information into Dictionary<string,object> and List<object> e.g.
// "[1,2,3]".FromJson<object>().GetType() == typeof(List<object>)
// "{\"Value\":10}".FromJson<object>().GetType() == typeof(Dictionary<string,object>)
// - No JIT Emit support to support AOT compilation on iOS
// - Attempts are made to NOT throw an exception if the JSON is corrupted or invalid: returns null instead.
// - Only public fields and property setters on classes/structs will be written to
//
// Limitations:
// - No JIT Emit support to parse structures quickly
// - Limited to parsing <2GB JSON files (due to int.MaxValue)
// - Parsing of abstract classes or interfaces is NOT supported and will throw an exception.
public static class JSONParser
{
[ThreadStatic] static Stack<List<string>> splitArrayPool;
[ThreadStatic] static StringBuilder stringBuilder;
[ThreadStatic] static Dictionary<Type, Dictionary<string, FieldInfo>> fieldInfoCache;
[ThreadStatic] static Dictionary<Type, Dictionary<string, PropertyInfo>> propertyInfoCache;
public static T FromJson<T>(this string json)
{
// Initialize, if needed, the ThreadStatic variables
if (propertyInfoCache == null) propertyInfoCache = new Dictionary<Type, Dictionary<string, PropertyInfo>>();
if (fieldInfoCache == null) fieldInfoCache = new Dictionary<Type, Dictionary<string, FieldInfo>>();
if (stringBuilder == null) stringBuilder = new StringBuilder();
if (splitArrayPool == null) splitArrayPool = new Stack<List<string>>();
//Remove all whitespace not within strings to make parsing simpler
stringBuilder.Length = 0;
for (int i = 0; i < json.Length; i++)
{
char c = json[i];
if (c == '"')
{
i = AppendUntilStringEnd(true, i, json);
continue;
}
if (char.IsWhiteSpace(c))
continue;
stringBuilder.Append(c);
}
//Parse the thing!
return (T)ParseValue(typeof(T), stringBuilder.ToString());
}
static int AppendUntilStringEnd(bool appendEscapeCharacter, int startIdx, string json)
{
stringBuilder.Append(json[startIdx]);
for (int i = startIdx + 1; i < json.Length; i++)
{
if (json[i] == '\\')
{
if (appendEscapeCharacter)
stringBuilder.Append(json[i]);
stringBuilder.Append(json[i + 1]);
i++;//Skip next character as it is escaped
}
else if (json[i] == '"')
{
stringBuilder.Append(json[i]);
return i;
}
else
stringBuilder.Append(json[i]);
}
return json.Length - 1;
}
//Splits { <value>:<value>, <value>:<value> } and [ <value>, <value> ] into a list of <value> strings
static List<string> Split(string json)
{
List<string> splitArray = splitArrayPool.Count > 0 ? splitArrayPool.Pop() : new List<string>();
splitArray.Clear();
if (json.Length == 2)
return splitArray;
int parseDepth = 0;
stringBuilder.Length = 0;
for (int i = 1; i < json.Length - 1; i++)
{
switch (json[i])
{
case '[':
case '{':
parseDepth++;
break;
case ']':
case '}':
parseDepth--;
break;
case '"':
i = AppendUntilStringEnd(true, i, json);
continue;
case ',':
case ':':
if (parseDepth == 0)
{
splitArray.Add(stringBuilder.ToString());
stringBuilder.Length = 0;
continue;
}
break;
}
stringBuilder.Append(json[i]);
}
splitArray.Add(stringBuilder.ToString());
return splitArray;
}
internal static object ParseValue(Type type, string json)
{
if (type == typeof(string))
{
if (json.Length <= 2)
return string.Empty;
StringBuilder parseStringBuilder = new StringBuilder(json.Length);
for (int i = 1; i < json.Length - 1; ++i)
{
if (json[i] == '\\' && i + 1 < json.Length - 1)
{
int j = "\"\\nrtbf/".IndexOf(json[i + 1]);
if (j >= 0)
{
parseStringBuilder.Append("\"\\\n\r\t\b\f/"[j]);
++i;
continue;
}
if (json[i + 1] == 'u' && i + 5 < json.Length - 1)
{
UInt32 c = 0;
if (UInt32.TryParse(json.Substring(i + 2, 4), System.Globalization.NumberStyles.AllowHexSpecifier, null, out c))
{
parseStringBuilder.Append((char)c);
i += 5;
continue;
}
}
}
parseStringBuilder.Append(json[i]);
}
return parseStringBuilder.ToString();
}
if (type.IsPrimitive)
{
var result = Convert.ChangeType(json, type, System.Globalization.CultureInfo.InvariantCulture);
return result;
}
if (type == typeof(decimal))
{
decimal result;
decimal.TryParse(json, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out result);
return result;
}
if (type == typeof(DateTime))
{
DateTime result;
DateTime.TryParse(json.Replace("\"",""), System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out result);
return result;
}
if (json == "null")
{
return null;
}
if (type.IsEnum)
{
if (json[0] == '"')
json = json.Substring(1, json.Length - 2);
try
{
return Enum.Parse(type, json, false);
}
catch
{
return 0;
}
}
if (type.IsArray)
{
Type arrayType = type.GetElementType();
if (json[0] != '[' || json[json.Length - 1] != ']')
return null;
List<string> elems = Split(json);
Array newArray = Array.CreateInstance(arrayType, elems.Count);
for (int i = 0; i < elems.Count; i++)
newArray.SetValue(ParseValue(arrayType, elems[i]), i);
splitArrayPool.Push(elems);
return newArray;
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
{
Type listType = type.GetGenericArguments()[0];
if (json[0] != '[' || json[json.Length - 1] != ']')
return null;
List<string> elems = Split(json);
var list = (IList)type.GetConstructor(new Type[] { typeof(int) }).Invoke(new object[] { elems.Count });
for (int i = 0; i < elems.Count; i++)
list.Add(ParseValue(listType, elems[i]));
splitArrayPool.Push(elems);
return list;
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
Type keyType, valueType;
{
Type[] args = type.GetGenericArguments();
keyType = args[0];
valueType = args[1];
}
//Refuse to parse dictionary keys that aren't of type string
if (keyType != typeof(string))
return null;
//Must be a valid dictionary element
if (json[0] != '{' || json[json.Length - 1] != '}')
return null;
//The list is split into key/value pairs only, this means the split must be divisible by 2 to be valid JSON
List<string> elems = Split(json);
if (elems.Count % 2 != 0)
return null;
var dictionary = (IDictionary)type.GetConstructor(new Type[] { typeof(int) }).Invoke(new object[] { elems.Count / 2 });
for (int i = 0; i < elems.Count; i += 2)
{
if (elems[i].Length <= 2)
continue;
string keyValue = elems[i].Substring(1, elems[i].Length - 2);
object val = ParseValue(valueType, elems[i + 1]);
dictionary[keyValue] = val;
}
return dictionary;
}
if (type == typeof(object))
{
return ParseAnonymousValue(json);
}
if (json[0] == '{' && json[json.Length - 1] == '}')
{
return ParseObject(type, json);
}
return null;
}
static object ParseAnonymousValue(string json)
{
if (json.Length == 0)
return null;
if (json[0] == '{' && json[json.Length - 1] == '}')
{
List<string> elems = Split(json);
if (elems.Count % 2 != 0)
return null;
var dict = new Dictionary<string, object>(elems.Count / 2);
for (int i = 0; i < elems.Count; i += 2)
dict[elems[i].Substring(1, elems[i].Length - 2)] = ParseAnonymousValue(elems[i + 1]);
return dict;
}
if (json[0] == '[' && json[json.Length - 1] == ']')
{
List<string> items = Split(json);
var finalList = new List<object>(items.Count);
for (int i = 0; i < items.Count; i++)
finalList.Add(ParseAnonymousValue(items[i]));
return finalList;
}
if (json[0] == '"' && json[json.Length - 1] == '"')
{
string str = json.Substring(1, json.Length - 2);
return str.Replace("\\", string.Empty);
}
if (char.IsDigit(json[0]) || json[0] == '-')
{
if (json.Contains("."))
{
double result;
double.TryParse(json, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out result);
return result;
}
else
{
int result;
int.TryParse(json, out result);
return result;
}
}
if (json == "true")
return true;
if (json == "false")
return false;
// handles json == "null" as well as invalid JSON
return null;
}
static Dictionary<string, T> CreateMemberNameDictionary<T>(T[] members) where T : MemberInfo
{
Dictionary<string, T> nameToMember = new Dictionary<string, T>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < members.Length; i++)
{
T member = members[i];
if (member.IsDefined(typeof(IgnoreDataMemberAttribute), true))
continue;
string name = member.Name;
if (member.IsDefined(typeof(DataMemberAttribute), true))
{
DataMemberAttribute dataMemberAttribute = (DataMemberAttribute)Attribute.GetCustomAttribute(member, typeof(DataMemberAttribute), true);
if (!string.IsNullOrEmpty(dataMemberAttribute.Name))
name = dataMemberAttribute.Name;
}
nameToMember.Add(name, member);
}
return nameToMember;
}
static object ParseObject(Type type, string json)
{
object instance = FormatterServices.GetUninitializedObject(type);
//The list is split into key/value pairs only, this means the split must be divisible by 2 to be valid JSON
List<string> elems = Split(json);
if (elems.Count % 2 != 0)
return instance;
Dictionary<string, FieldInfo> nameToField;
Dictionary<string, PropertyInfo> nameToProperty;
if (!fieldInfoCache.TryGetValue(type, out nameToField))
{
nameToField = CreateMemberNameDictionary(type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy));
fieldInfoCache.Add(type, nameToField);
}
if (!propertyInfoCache.TryGetValue(type, out nameToProperty))
{
nameToProperty = CreateMemberNameDictionary(type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy));
propertyInfoCache.Add(type, nameToProperty);
}
for (int i = 0; i < elems.Count; i += 2)
{
if (elems[i].Length <= 2)
continue;
string key = elems[i].Substring(1, elems[i].Length - 2);
string value = elems[i + 1];
FieldInfo fieldInfo;
PropertyInfo propertyInfo;
if (nameToField.TryGetValue(key, out fieldInfo))
fieldInfo.SetValue(instance, ParseValue(fieldInfo.FieldType, value));
else if (nameToProperty.TryGetValue(key, out propertyInfo))
propertyInfo.SetValue(instance, ParseValue(propertyInfo.PropertyType, value), null);
}
return instance;
}
}
}

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace vCardEditor.Libs.TinyJson
{
public class LocalizationFile
{
public string version;
public Dictionary<string, LanguageData> languages = new Dictionary<string, LanguageData>();
}
public class LanguageData
{
public string name;
public Dictionary<string, string> messages = new Dictionary<string, string>();
}
}

View File

@@ -0,0 +1,30 @@
using vCardEditor.Repository;
namespace vCardEditor.Libs.TinyJson
{
public class LocalizationLoader
{
private readonly IParser _parser;
private readonly IFileHandler _fileHandler;
public LocalizationLoader(IParser parser, IFileHandler fileHandler)
{
_parser = parser;
_fileHandler = fileHandler;
}
public LocalizationFile LoadEmbedded(string EmbeddedResourceName = "vCardEditor.i18n.lang.json")
{
string json = _fileHandler.LoadJsonFromAssembly(EmbeddedResourceName);
return Deserialize(json);
}
private LocalizationFile Deserialize(string json)
{
var result = _parser.Deserialize<LocalizationFile>(json);
return result ?? new LocalizationFile();
}
}
}

View File

@@ -0,0 +1,12 @@
using TinyJson;
namespace vCardEditor.Libs.TinyJson
{
public class TinyJsonParser : IParser
{
public T Deserialize<T>(string json)
{
return JSONParser.FromJson<T>(json);
}
}
}

View File

@@ -15,6 +15,7 @@ namespace VCFEditor.Model
NotifyPropertyChanged("Name");
}
}
[DisplayName("F.Name")]
public string FamilyName
{
@@ -27,12 +28,10 @@ namespace VCFEditor.Model
get {
if (card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) != null)
return card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber;
return string.Empty;
}
}
[Browsable(false)]
public vCard card { get; set; }
@@ -44,7 +43,9 @@ namespace VCFEditor.Model
[Browsable(false)]
public bool isDeleted { get; set; }
[Browsable(false)]
public string path { get; set; }
public Contact()
{
@@ -53,6 +54,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));

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace vCardEditor.Model
{
@@ -16,10 +15,9 @@ namespace vCardEditor.Model
get { return _size; }
set { _size = value; }
}
public FixedList() : this(5)
{
}
public FixedList() { }
public FixedList(int size)
{
this._size = size;

View File

@@ -1,13 +1,13 @@
using System;
using Thought.vCards;
using VCFEditor.View;
using vCardEditor.View;
using VCFEditor.Repository;
using vCardEditor.Repository;
using vCardEditor.Model;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Thought.vCards;
using vCardEditor;
using vCardEditor.Model;
using vCardEditor.Repository;
using vCardEditor.View.Customs;
using VCFEditor.Repository;
using VCFEditor.View;
namespace VCFEditor.Presenter
{
@@ -15,15 +15,17 @@ namespace VCFEditor.Presenter
{
private readonly IMainView _view;
private readonly IContactRepository _repository;
private readonly ILocalizationProvider _localization;
public MainPresenter(IMainView view, IContactRepository repository)
public MainPresenter(IMainView view, IContactRepository repository, ILocalizationProvider localization )
{
_view = view;
_repository = repository;
_localization = localization;
_view.LoadForm += LoadFormHandler;
_view.AddContact += AddContactHandler;
_view.NewFileOpened += NewFileOpenedHandler;
_view.NewFileOpened += OpenNewFileHandler;
_view.SaveContactsSelected += SaveContactsHandler;
_view.ChangeContactsSelected += ChangeContactSelectedHandler;
_view.DeleteContact += DeleteContactHandler;
@@ -39,7 +41,129 @@ namespace VCFEditor.Presenter
_view.AddressRemoved += AddressRemovedHandler;
_view.CopyTextToClipboardEvent += CopyTextToClipboardHandler;
_view.AddExtraField += _view_AddExtraField;
_view.CountImagesEvent += _view_CountImages;
_view.ClearImagesEvent += _view_ClearImages;
_view.BatchExportImagesEvent += _view_BatchExportImagesEvent;
_view.SplitFileEvent += SaveSplittedFileHandler;
_view.OpenFolderEvent += OpenNewFolderHandler;
_view.CardInfoRemoved += CardInfoRemovedHandler;
}
private void OpenNewFolderHandler(object sender, EventArg<string> e)
{
BeforeOpeningNewFileHandler();
string path = e.Data;
if (string.IsNullOrEmpty(path))
path = _view.DisplayOpenFolderDialog();
if (!string.IsNullOrEmpty(path))
{
bool 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)
return;
int count = 0;
for (int i = 0; i < _repository.Contacts.Count; i++)
{
if (_repository.Contacts[i].card.Photos.Count > 0)
{
count++;
SaveCardPhoto(_repository.Contacts[i].card, i);
}
}
if (count > 0)
_view.DisplayMessage($"{count} contact(s) processed!", "Photo Count");
else
_view.DisplayMessage($"No picture found!", "Photo Count");
}
private void _view_ClearImages(object sender, EventArgs e)
{
if (_repository.Contacts == null || _repository.Contacts.Count == 0)
return;
int count = 0;
for (int i = 0; i < _repository.Contacts.Count; i++)
{
if (_repository.Contacts[i].card.Photos.Count > 0)
{
count++;
_repository.ModifyImage(i, null);
//remove from the form the image displayed.
if (_view.SelectedContactIndex == i)
_view.ClearImageFromForm();
}
}
if (count > 0)
_view.DisplayMessage($"{count} contact(s) processed!", "Photo Count");
else
_view.DisplayMessage($"No picture found!", "Photo Count");
}
private void _view_CountImages(object sender, EventArgs e)
{
if (_repository.Contacts == null)
return;
int count = _repository.Contacts.Count(x => x.card.Photos.Count > 0);
if (count > 0)
_view.DisplayMessage($"{count} contact(s) containing a picture = ", "Photo Count");
else
_view.DisplayMessage($"No picture found!", "Photo Count");
}
private void _view_AddExtraField(object sender, EventArg<vCardPropeties> e)
@@ -59,19 +183,20 @@ namespace VCFEditor.Presenter
_view.SendTextToClipBoard(SerializedCard);
_view.DisplayMessage("vCard copied to clipboard!", "Information");
}
private void LoadFormHandler(object sender, EventArg<FormState> e)
{
_view.LoadIntialState(ConfigRepository.Instance.FormState);
var paths = Environment.GetCommandLineArgs();
_view.LoadAvailablesLangs(_localization.AvailableLanguages);
_view.LoadLocalizedUI(_localization.CurrentMessages);
string[] paths = Environment.GetCommandLineArgs();
if (paths.Length > 1)
{
var evt = new EventArg<string>(paths[1]);
NewFileOpenedHandler(sender, evt);
OpenNewFileHandler(sender, evt);
}
}
private void AddressRemovedHandler(object sender, EventArg<int> e)
{
var contact = _repository.Contacts[_view.SelectedContactIndex];
@@ -85,7 +210,7 @@ namespace VCFEditor.Presenter
var contact = _repository.Contacts[_view.SelectedContactIndex];
_repository.SetDirtyFlag(_view.SelectedContactIndex);
contact.card.DeliveryAddresses.Add(new vCardDeliveryAddress( e.Data));
contact.card.DeliveryAddresses.Add(new vCardDeliveryAddress(e.Data));
}
private void AddressModifiedHandler(object sender, EventArg<List<vCardDeliveryAddressTypes>> e)
@@ -96,32 +221,39 @@ namespace VCFEditor.Presenter
contact.card.DeliveryAddresses.Clear();
contact.card.DeliveryAddresses.Add(new vCardDeliveryAddress(e.Data));
}
private void ExportImageHandler(object sender, EventArgs e)
{
if (_view.SelectedContactIndex > -1)
{
//TODO: image can be url, or file location.
var card = _repository.Contacts[_view.SelectedContactIndex].card;
var image = card.Photos.FirstOrDefault();
vCard card = _repository.Contacts[_view.SelectedContactIndex].card;
SaveCardPhoto(card, _view.SelectedContactIndex, true);
}
}
if (image != null)
{
var newPath = _repository.ChangeExtension(_repository.fileName, image.Extension);
private void SaveCardPhoto(vCard card, int index, bool askUser = false)
{
//TODO: Save every image for a vCard.
vCardPhoto image = card.Photos.FirstOrDefault();
string imageFile = _view.DisplaySaveDialog(newPath);
_repository.SaveImageToDisk(imageFile, image);
}
if (image != null)
{
string newPath = _repository.GenerateFileName(_repository.fileName, index, image.Extension);
//string ImagePath = string.Empty;
//if (askUser)
// ImagePath = _view.DisplaySaveDialog(newPath);
_repository.SaveImageToDisk(newPath, image);
}
}
private void ExportQRHandler(object sender, EventArgs e)
{
if (_view.SelectedContactIndex > -1)
{
var card = _repository.Contacts[_view.SelectedContactIndex].card;
vCard card = _repository.Contacts[_view.SelectedContactIndex].card;
string content = _repository.GenerateStringFromVCard(card);
_view.DisplayQRCode(content);
@@ -130,29 +262,28 @@ namespace VCFEditor.Presenter
private void ModifyImageHandler(object sender, EventArg<string> e)
{
if (!string.IsNullOrEmpty(e.Data) )
if (!string.IsNullOrEmpty(e.Data))
{
vCardPhoto photo = new vCardPhoto(e.Data);
_repository.ModifyImage(_view.SelectedContactIndex, photo);
}
else
_repository.ModifyImage(_view.SelectedContactIndex, null);
}
void CloseFormHandler(object sender, EventArg<bool> e)
{
if (_repository.dirty && _view.AskMessage("Exit without saving?", "Exit"))
if (_repository.dirty && !_view.AskMessage("Exit without saving?", "Exit"))
e.Data = true;
if (!e.Data)
{
var state = _view.GetFormState();
FormState state = _view.GetFormState();
ConfigRepository.Instance.FormState = state;
ConfigRepository.Instance.SaveConfig();
}
}
public void BeforeLeavingContactHandler(object sender, EventArg<vCard> e)
{
_repository.SaveDirtyVCard(_view.SelectedContactIndex, e.Data);
@@ -160,10 +291,14 @@ namespace VCFEditor.Presenter
public void TextBoxValueChangedHandler(object sender, EventArgs e)
{
var tb = sender as StateTextBox;
StateTextBox tb = sender as StateTextBox;
if (tb != null && tb.oldText != tb.Text)
_repository.SetDirtyFlag(_view.SelectedContactIndex);
}
public void CardInfoRemovedHandler(object sender, EventArgs e)
{
_repository.SetDirtyFlag(_view.SelectedContactIndex);
}
public void FilterTextChangedHandler(object sender, EventArg<string> e)
@@ -175,6 +310,7 @@ namespace VCFEditor.Presenter
private void AddContactHandler(object sender, EventArgs e)
{
_repository.AddEmptyContact();
_view.DisplayContacts(_repository.Contacts);
}
private void DeleteContactHandler(object sender, EventArgs e)
@@ -184,56 +320,38 @@ namespace VCFEditor.Presenter
private void SaveContactsHandler(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(_repository.fileName))
_repository.SaveContactsToFile(_repository.fileName);
string filename = _repository.fileName ?? _view.DisplaySaveDialog();
if (string.IsNullOrWhiteSpace(filename))
return;
_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");
}
}
private void BeforeOpeningNewFileHandler()
{
if (_repository.Contacts != null && _repository.dirty)
{
if (!_view.AskMessage("Save current file before?", "Load"))
_repository.SaveContactsToFile(_repository.fileName);
if (_view.AskMessage("Save current file before?", "Load"))
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)
{
if (_view.SelectedContactIndex > -1)
{
vCard card = _repository.Contacts[_view.SelectedContactIndex].card;
@@ -245,8 +363,6 @@ namespace VCFEditor.Presenter
}
else
_view.ClearContactDetail();
}
}
}

View File

@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using vCardEditor.Libs.TinyJson;
using vCardEditor.Repository;
using vCardEditor.View;
using VCFEditor.Presenter;
using VCFEditor;
using VCFEditor.Repository;
using vCardEditor.Repository;
namespace vCardEditor
{
@@ -20,10 +18,14 @@ namespace vCardEditor
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
FileHandler fileHandler = new FileHandler();
var fileHandler = new FileHandler();
var mainForm = new MainForm();
new MainPresenter(mainForm, new ContactRepository(fileHandler));
var embeddedlang = new LocalizationLoader(new TinyJsonParser(), fileHandler).LoadEmbedded();
MainForm mainForm = new MainForm();
new MainPresenter(mainForm,
new ContactRepository(fileHandler),
new JsonLocalizationProvider(embeddedlang));
Application.Run(mainForm);
}

View File

@@ -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.3")]
[assembly: AssemblyVersion("0.5.8")]

View File

@@ -1,5 +1,22 @@
0.5.4
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
0.5.4
Fix a regression when saving Phones, Website, Email
added the update button in the about dialog to check the latest version.
0.5.3
Support of QR Code.
@@ -25,4 +42,4 @@
Replaced Moq with nsubstitute (Test mocking library).
0.1
Intial release
Intial release

View File

@@ -17,6 +17,7 @@ namespace vCardEditor.Repository
private const int MAX_RECENT_FILES = 5;
private static ConfigRepository instance = null;
[XmlIgnore]
public static ConfigRepository Instance
{
@@ -30,10 +31,14 @@ namespace vCardEditor.Repository
}
[Description("Overwrite the file when saving")]
public bool OverWrite { get; set; }
public bool Overwrite { get; set; }
[Description("Maximum entries for MRU ")]
public int Maximum { get; set; }
[Description("Url for checking application version")]
public string VersionUrl { get; set; }
[Browsable(false)]
public FixedList Paths { get; set; }
@@ -42,14 +47,12 @@ namespace vCardEditor.Repository
private ConfigRepository() { }
/// <summary>
/// save config file
/// </summary>
public void SaveConfig()
{
var ns = new XmlSerializerNamespaces();
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer xsSubmit = new XmlSerializer(typeof(ConfigRepository));
@@ -79,21 +82,18 @@ namespace vCardEditor.Repository
configData = (ConfigRepository)deserializer.Deserialize(reader);
configData.Paths.Size = configData.Maximum;
}
}
catch (Exception)
{
configData = new ConfigRepository
{
Maximum = MAX_RECENT_FILES,
Paths = new FixedList(MAX_RECENT_FILES)
Paths = new FixedList(MAX_RECENT_FILES),
VersionUrl = "https://raw.githubusercontent.com/abdelkader/vCardEditor/master/vCardEditor/Releases.txt"
};
}
return configData;
}
}
}

View File

@@ -3,10 +3,9 @@ using System.IO;
using System.Linq;
using System.Text;
using Thought.vCards;
using VCFEditor.Model;
using System.ComponentModel;
using vCardEditor.Repository;
using vCardEditor.View;
using VCFEditor.Model;
namespace VCFEditor.Repository
{
@@ -14,16 +13,13 @@ namespace VCFEditor.Repository
{
public string fileName { get; set; }
private IFileHandler _fileHandler;
/// <summary>
/// Formatted name.
/// </summary>
public const string KeyName = "FN";
/// <summary>
/// Keep a copy of contact list when filtering
/// </summary>
private SortableBindingList<Contact> OriginalContactList = null;
private SortableBindingList<Contact> _contacts;
public SortableBindingList<Contact> Contacts
{
get
@@ -44,52 +40,84 @@ namespace VCFEditor.Repository
get { return (_contacts != null && _contacts.Any(x => x.isDirty)) || _dirty; }
set { _dirty = true; }
}
public ContactRepository(IFileHandler fileHandler)
{
_fileHandler = fileHandler;
}
public bool LoadMultipleFilesContact(string path)
{
Contacts.Clear();
string[] filePaths = _fileHandler.GetFiles(path, "*.vcf");
if (filePaths.Count() == 0)
return false;
foreach (string 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();
Contact contact = new Contact();
Contact contact;
for (int i = 0; i < lines.Length; i++)
{
RawContent.AppendLine(lines[i]);
if (string.Equals(lines[i].TrimEnd(), "END:VCARD", StringComparison.OrdinalIgnoreCase))
try
{
contact.card = ParseRawContent(RawContent);
Contacts.Add(contact);
contact = new Contact();
RawContent.Length = 0;
if (string.Equals(lines[i].TrimEnd(), "END:VCARD", StringComparison.OrdinalIgnoreCase))
{
contact = new Contact(ParseRawContent(RawContent));
ListOfContacts.Add(contact);
RawContent.Length = 0;
}
}
catch (Exception)
{
return null;
}
}
OriginalContactList = Contacts;
return true;
return ListOfContacts;
}
private vCard ParseRawContent(StringBuilder rawContent)
{
vCard card = null;
using (StringReader reader = new StringReader(rawContent.ToString()))
card = new vCard(reader);
return card;
}
public void AddEmptyContact()
{
if (_contacts != null && _contacts.Count > 0)
{
Contact contact = new Contact();
Contacts.Add(contact);
}
Contacts.Add(new Contact() { isDirty = true });
}
public void SaveContactsToFile(string fileName)
@@ -99,7 +127,7 @@ namespace VCFEditor.Repository
fileName = this.fileName;
//Take a copy if specified in the config file
if (!ConfigRepository.Instance.OverWrite)
if (!ConfigRepository.Instance.Overwrite)
{
string backupName = GetBackupName();
_fileHandler.MoveFile(fileName, backupName);
@@ -107,7 +135,7 @@ namespace VCFEditor.Repository
StringBuilder sb = new StringBuilder();
foreach (var entry in Contacts)
foreach (Contact entry in Contacts)
{
//Do not save the deleted ones!
if (!entry.isDeleted)
@@ -119,8 +147,7 @@ namespace VCFEditor.Repository
//Clean the flag for every contact, even the deleted ones.
entry.isDirty = false;
}
_dirty = false;
_fileHandler.WriteAllText(fileName, sb.ToString());
}
@@ -150,33 +177,8 @@ namespace VCFEditor.Repository
_dirty = true;
_contacts.RemoveAt(i);
}
}
}
}
private vCard ParseRawContent(StringBuilder rawContent)
{
vCard card = null;
using (MemoryStream s = GenerateStreamFromString(rawContent.ToString()))
using (TextReader streamReader = new StreamReader(s, Encoding.UTF8))
{
card = new vCard(streamReader);
}
return card;
}
private MemoryStream GenerateStreamFromString(string s)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
public SortableBindingList<Contact> FilterContacts(string filter)
@@ -187,7 +189,6 @@ namespace VCFEditor.Repository
return Contacts;
}
public void SetDirtyFlag(int index)
{
if (index > -1)
@@ -218,25 +219,23 @@ namespace VCFEditor.Repository
private void SaveExtraPhones(vCard newCard, vCard card)
{
card.Phones.Clear();
foreach (var item in newCard.Phones)
foreach (vCardPhone item in newCard.Phones)
card.Phones.Add(new vCardPhone(item.FullNumber, item.PhoneType));
}
private void SaveExtraField(vCard newCard, vCard card)
{
card.Notes.Clear();
foreach (var item in newCard.Notes)
foreach (vCardNote item in newCard.Notes)
card.Notes.Add(new vCardNote(item.Text));
card.Organization = newCard.Organization;
}
private void SaveAddresses(vCard NewCard, vCard card)
{
foreach (var item in NewCard.DeliveryAddresses)
foreach (vCardDeliveryAddress item in NewCard.DeliveryAddresses)
{
var adr = card.DeliveryAddresses.Where(x => x.AddressType.FirstOrDefault() == item.AddressType.FirstOrDefault()).FirstOrDefault();
vCardDeliveryAddress adr = card.DeliveryAddresses.Where(x => x.AddressType.FirstOrDefault() == item.AddressType.FirstOrDefault()).FirstOrDefault();
if (adr != null)
{
adr.City = item.City;
@@ -250,7 +249,6 @@ namespace VCFEditor.Repository
else
card.DeliveryAddresses.Add(new vCardDeliveryAddress(item.Street, item.City, item.Region, item.Country,
item.PostalCode, item.AddressType.FirstOrDefault()));
}
}
@@ -268,10 +266,8 @@ namespace VCFEditor.Repository
{
if (card.Phones.GetFirstChoice(vCardPhoneTypes.Home) != null)
card.Phones.GetFirstChoice(vCardPhoneTypes.Home).FullNumber = string.Empty;
}
//Cellular
if (NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) != null)
{
@@ -284,7 +280,6 @@ namespace VCFEditor.Repository
{
if (card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) != null)
card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber = string.Empty;
}
//Work
@@ -299,7 +294,6 @@ namespace VCFEditor.Repository
{
if (card.Phones.GetFirstChoice(vCardPhoneTypes.Work) != null)
card.Phones.GetFirstChoice(vCardPhoneTypes.Work).FullNumber = string.Empty;
}
}
@@ -319,14 +313,12 @@ namespace VCFEditor.Repository
{
if (card.EmailAddresses.GetFirstChoice(vCardEmailAddressType.Internet) != null)
card.EmailAddresses.GetFirstChoice(vCardEmailAddressType.Internet).Address = string.Empty;
}
}
private void SaveWebUrl(vCard NewCard, vCard card)
{
//Personal
if (NewCard.Websites.GetFirstChoice(vCardWebsiteTypes.Personal) != null)
{
if (card.Websites.GetFirstChoice(vCardWebsiteTypes.Personal) != null)
@@ -338,32 +330,31 @@ namespace VCFEditor.Repository
{
if (card.Websites.GetFirstChoice(vCardWebsiteTypes.Personal) != null)
card.Websites.GetFirstChoice(vCardWebsiteTypes.Personal).Url = string.Empty;
}
if (NewCard.Websites.GetFirstChoice(vCardWebsiteTypes.Work) != null)
{
if (card.Websites.GetFirstChoice(vCardWebsiteTypes.Work) != null)
card.Websites.GetFirstChoice(vCardWebsiteTypes.Work).Url = NewCard.Websites.GetFirstChoice(vCardWebsiteTypes.Work).Url;
else
card.Websites.Add(new vCardWebsite(NewCard.Websites.GetFirstChoice(vCardWebsiteTypes.Work).Url, vCardWebsiteTypes.Work));
}
else
{
if (card.Websites.GetFirstChoice(vCardWebsiteTypes.Work) != null)
card.Websites.GetFirstChoice(vCardWebsiteTypes.Work).Url = string.Empty;
}
//Work
//if (NewCard.Websites.GetFirstChoice(vCardWebsiteTypes.Work) != null)
//{
// if (card.Websites.GetFirstChoice(vCardWebsiteTypes.Work) != null)
// card.Websites.GetFirstChoice(vCardWebsiteTypes.Work).Url = NewCard.Websites.GetFirstChoice(vCardWebsiteTypes.Work).Url;
// else
// card.Websites.Add(new vCardWebsite(NewCard.Websites.GetFirstChoice(vCardWebsiteTypes.Work).Url, vCardWebsiteTypes.Work));
//}
//else
//{
// if (card.Websites.GetFirstChoice(vCardWebsiteTypes.Work) != null)
// card.Websites.GetFirstChoice(vCardWebsiteTypes.Work).Url = string.Empty;
//}
}
public string GenerateStringFromVCard(vCard card)
{
vCardStandardWriter writer = new vCardStandardWriter();
TextWriter tw = new StringWriter();
writer.Write(card, tw);
return tw.ToString();
using (TextWriter tw = new StringWriter())
{
writer.Write(card, tw);
return tw.ToString();
}
}
public void ModifyImage(int index, vCardPhoto photo)
@@ -392,7 +383,47 @@ namespace VCFEditor.Repository
return _fileHandler.ChangeExtension(path, extension);
}
public string GenerateFileName(string fileName, int index, string extension)
{
return _fileHandler.GetFileNameWithExtension(fileName, index, extension);
}
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++)
{
Contact 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;
}
}
}

View File

@@ -1,5 +1,5 @@
using System.IO;
using System.Reflection;
namespace vCardEditor.Repository
{
@@ -22,7 +22,8 @@ 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)
@@ -37,11 +38,41 @@ namespace vCardEditor.Repository
public void WriteBytesToFile(string imageFile, byte[] image)
{
using (var ms = new MemoryStream(image))
using (MemoryStream ms = new MemoryStream(image))
{
using (var fs = new FileStream(imageFile, FileMode.Create))
using (FileStream fs = new FileStream(imageFile, FileMode.Create))
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)
{
return Directory.GetFiles(path, ext, SearchOption.TopDirectoryOnly);
}
public string LoadJsonFromAssembly(string EmbeddedResourceName)
{
string json;
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(EmbeddedResourceName))
{
if (stream == null)
throw new FileNotFoundException($"Embedded resource '{EmbeddedResourceName}' not found.");
using (StreamReader reader = new StreamReader(stream))
json = reader.ReadToEnd();
}
return json;
}
}
}

View File

@@ -5,7 +5,7 @@ namespace vCardEditor.Repository
public interface IConfigRepository
{
int Maximum { get; set; }
bool OverWrite { get; set; }
bool Overwrite { get; set; }
FixedList Paths { get; set; }
void SaveConfig();

View File

@@ -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();
@@ -23,9 +20,12 @@ namespace VCFEditor.Repository
void AddEmptyContact();
void ModifyImage(int index, vCardPhoto photo);
string GetExtension(string path);
string ChangeExtension(string path, string extension);
//string ChangeExtension(string path, int index, string extension);
void SaveImageToDisk(string imageFile, vCardPhoto image);
string GenerateStringFromVCard(vCard card);
string GenerateFileName(string fileName, int index, string extension);
int SaveSplittedFiles(string Path);
}
}

View File

@@ -1,4 +1,6 @@
namespace vCardEditor.Repository
using System.IO;
namespace vCardEditor.Repository
{
public interface IFileHandler
{
@@ -9,5 +11,9 @@
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 LoadJsonFromAssembly(string EmbeddedResourceName);
string[] GetFiles(string path, string ext);
}
}

View File

@@ -1,90 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Ce code a été généré par un outil.
// Version du runtime :4.0.30319.34209
//
// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
// le code est régénéré.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Thought.vCards {
using System;
/// <summary>
/// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
/// </summary>
// Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder
// à l'aide d'un outil, tel que ResGen ou Visual Studio.
// Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen
// avec l'option /str ou régénérez votre projet VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class WarningMessages {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal WarningMessages() {
}
/// <summary>
/// Retourne l'instance ResourceManager mise en cache utilisée par cette classe.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("vCardEditor.Thought.vCards.WarningMessages", typeof(WarningMessages).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Remplace la propriété CurrentUICulture du thread actuel pour toutes
/// les recherches de ressources à l'aide de cette classe de ressource fortement typée.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à Line {0} A blank line was encountered. This is not allowed in the vCard specification..
/// </summary>
internal static string BlankLine {
get {
return ResourceManager.GetString("BlankLine", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à Line {0}: A colon (:) is missing. All properties must be in NAME:VALUE format..
/// </summary>
internal static string ColonMissing {
get {
return ResourceManager.GetString("ColonMissing", resourceCulture);
}
}
/// <summary>
/// Recherche une chaîne localisée semblable à Line {0}: The name section of the property is empty..
/// </summary>
internal static string EmptyName {
get {
return ResourceManager.GetString("EmptyName", resourceCulture);
}
}
}
}

View File

@@ -1,129 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BlankLine" xml:space="preserve">
<value>Line {0} A blank line was encountered. This is not allowed in the vCard specification.</value>
</data>
<data name="ColonMissing" xml:space="preserve">
<value>Line {0}: A colon (:) is missing. All properties must be in NAME:VALUE format.</value>
</data>
<data name="EmptyName" xml:space="preserve">
<value>Line {0}: The name section of the property is empty.</value>
</data>
</root>

View File

@@ -36,137 +36,154 @@
this.labelCompanyName = new System.Windows.Forms.Label();
this.textBoxDescription = new System.Windows.Forms.TextBox();
this.okButton = new System.Windows.Forms.Button();
this.updateButton = new System.Windows.Forms.Button();
this.tableLayoutPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).BeginInit();
this.SuspendLayout();
//
// tableLayoutPanel
//
this.tableLayoutPanel.ColumnCount = 2;
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 27.81775F));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 72.18225F));
this.tableLayoutPanel.ColumnCount = 3;
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 32.31441F));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 67.68559F));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 90F));
this.tableLayoutPanel.Controls.Add(this.logoPictureBox, 0, 0);
this.tableLayoutPanel.Controls.Add(this.labelProductName, 1, 0);
this.tableLayoutPanel.Controls.Add(this.labelVersion, 1, 1);
this.tableLayoutPanel.Controls.Add(this.labelCopyright, 1, 2);
this.tableLayoutPanel.Controls.Add(this.labelCompanyName, 1, 3);
this.tableLayoutPanel.Controls.Add(this.textBoxDescription, 1, 4);
this.tableLayoutPanel.Controls.Add(this.okButton, 1, 5);
this.tableLayoutPanel.Controls.Add(this.okButton, 2, 5);
this.tableLayoutPanel.Controls.Add(this.updateButton, 1, 5);
this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel.Location = new System.Drawing.Point(12, 11);
this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(4);
this.tableLayoutPanel.Location = new System.Drawing.Point(9, 9);
this.tableLayoutPanel.Name = "tableLayoutPanel";
this.tableLayoutPanel.RowCount = 6;
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
this.tableLayoutPanel.Size = new System.Drawing.Size(556, 326);
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 47.93651F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 12.69841F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 16F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 16F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 16F));
this.tableLayoutPanel.Size = new System.Drawing.Size(417, 265);
this.tableLayoutPanel.TabIndex = 0;
//
// logoPictureBox
//
this.logoPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("logoPictureBox.Image")));
this.logoPictureBox.Location = new System.Drawing.Point(4, 4);
this.logoPictureBox.Margin = new System.Windows.Forms.Padding(4);
this.logoPictureBox.Location = new System.Drawing.Point(3, 3);
this.logoPictureBox.Name = "logoPictureBox";
this.tableLayoutPanel.SetRowSpan(this.logoPictureBox, 6);
this.logoPictureBox.Size = new System.Drawing.Size(145, 121);
this.logoPictureBox.Size = new System.Drawing.Size(99, 98);
this.logoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.logoPictureBox.TabIndex = 12;
this.logoPictureBox.TabStop = false;
//
// labelProductName
//
this.tableLayoutPanel.SetColumnSpan(this.labelProductName, 2);
this.labelProductName.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelProductName.Location = new System.Drawing.Point(162, 0);
this.labelProductName.Margin = new System.Windows.Forms.Padding(8, 0, 4, 0);
this.labelProductName.MaximumSize = new System.Drawing.Size(0, 21);
this.labelProductName.Location = new System.Drawing.Point(111, 0);
this.labelProductName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelProductName.MaximumSize = new System.Drawing.Size(0, 17);
this.labelProductName.Name = "labelProductName";
this.labelProductName.Size = new System.Drawing.Size(390, 21);
this.labelProductName.Size = new System.Drawing.Size(303, 17);
this.labelProductName.TabIndex = 19;
this.labelProductName.Text = "Nom du produit";
this.labelProductName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelVersion
//
this.tableLayoutPanel.SetColumnSpan(this.labelVersion, 2);
this.labelVersion.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelVersion.Location = new System.Drawing.Point(162, 32);
this.labelVersion.Margin = new System.Windows.Forms.Padding(8, 0, 4, 0);
this.labelVersion.MaximumSize = new System.Drawing.Size(0, 21);
this.labelVersion.Location = new System.Drawing.Point(111, 26);
this.labelVersion.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelVersion.MaximumSize = new System.Drawing.Size(0, 17);
this.labelVersion.Name = "labelVersion";
this.labelVersion.Size = new System.Drawing.Size(390, 21);
this.labelVersion.Size = new System.Drawing.Size(303, 17);
this.labelVersion.TabIndex = 0;
this.labelVersion.Text = "Version";
this.labelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelCopyright
//
this.tableLayoutPanel.SetColumnSpan(this.labelCopyright, 2);
this.labelCopyright.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelCopyright.Location = new System.Drawing.Point(162, 64);
this.labelCopyright.Margin = new System.Windows.Forms.Padding(8, 0, 4, 0);
this.labelCopyright.MaximumSize = new System.Drawing.Size(0, 21);
this.labelCopyright.Location = new System.Drawing.Point(111, 52);
this.labelCopyright.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelCopyright.MaximumSize = new System.Drawing.Size(0, 17);
this.labelCopyright.Name = "labelCopyright";
this.labelCopyright.Size = new System.Drawing.Size(390, 21);
this.labelCopyright.Size = new System.Drawing.Size(303, 17);
this.labelCopyright.TabIndex = 21;
this.labelCopyright.Text = "Copyright";
this.labelCopyright.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelCompanyName
//
this.tableLayoutPanel.SetColumnSpan(this.labelCompanyName, 2);
this.labelCompanyName.Dock = System.Windows.Forms.DockStyle.Fill;
this.labelCompanyName.Location = new System.Drawing.Point(162, 96);
this.labelCompanyName.Margin = new System.Windows.Forms.Padding(8, 0, 4, 0);
this.labelCompanyName.MaximumSize = new System.Drawing.Size(0, 21);
this.labelCompanyName.Location = new System.Drawing.Point(111, 78);
this.labelCompanyName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0);
this.labelCompanyName.MaximumSize = new System.Drawing.Size(0, 17);
this.labelCompanyName.Name = "labelCompanyName";
this.labelCompanyName.Size = new System.Drawing.Size(390, 21);
this.labelCompanyName.Size = new System.Drawing.Size(303, 17);
this.labelCompanyName.TabIndex = 22;
this.labelCompanyName.Text = "Nom de la société";
this.labelCompanyName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// textBoxDescription
//
this.tableLayoutPanel.SetColumnSpan(this.textBoxDescription, 2);
this.textBoxDescription.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxDescription.Location = new System.Drawing.Point(162, 132);
this.textBoxDescription.Margin = new System.Windows.Forms.Padding(8, 4, 4, 4);
this.textBoxDescription.Location = new System.Drawing.Point(111, 107);
this.textBoxDescription.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3);
this.textBoxDescription.Multiline = true;
this.textBoxDescription.Name = "textBoxDescription";
this.textBoxDescription.ReadOnly = true;
this.textBoxDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBoxDescription.Size = new System.Drawing.Size(390, 155);
this.textBoxDescription.Size = new System.Drawing.Size(303, 120);
this.textBoxDescription.TabIndex = 23;
this.textBoxDescription.TabStop = false;
this.textBoxDescription.Text = "Description";
//
// okButton
//
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.okButton.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.okButton.Location = new System.Drawing.Point(452, 295);
this.okButton.Margin = new System.Windows.Forms.Padding(4);
this.okButton.Location = new System.Drawing.Point(332, 235);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(100, 27);
this.okButton.Size = new System.Drawing.Size(82, 24);
this.okButton.TabIndex = 24;
this.okButton.Text = "&OK";
//
// updateButton
//
this.updateButton.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.updateButton.Location = new System.Drawing.Point(233, 235);
this.updateButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.updateButton.Name = "updateButton";
this.updateButton.Size = new System.Drawing.Size(91, 24);
this.updateButton.TabIndex = 25;
this.updateButton.Text = "Check update...";
this.updateButton.Click += new System.EventHandler(this.updateButton_Click);
//
// AboutDialog
//
this.AcceptButton = this.okButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(580, 348);
this.ClientSize = new System.Drawing.Size(435, 283);
this.Controls.Add(this.tableLayoutPanel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Margin = new System.Windows.Forms.Padding(4);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AboutDialog";
this.Padding = new System.Windows.Forms.Padding(12, 11, 12, 11);
this.Padding = new System.Windows.Forms.Padding(9, 9, 9, 9);
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
@@ -188,5 +205,6 @@
private System.Windows.Forms.Label labelCompanyName;
private System.Windows.Forms.TextBox textBoxDescription;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button updateButton;
}
}

View File

@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Net;
using System.Reflection;
using System.Windows.Forms;
using vCardEditor.Repository;
namespace vCardEditor.View
{
@@ -36,7 +35,7 @@ namespace vCardEditor.View
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
@@ -100,5 +99,36 @@ namespace vCardEditor.View
}
}
#endregion
private async void updateButton_Click(object sender, EventArgs e)
{
try
{
using (WebClient client = new WebClient())
{
string result = await client.DownloadStringTaskAsync(ConfigRepository.Instance.VersionUrl);
using (StringReader reader = new StringReader(result))
{
string InternetVersion = reader.ReadLine();
string AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Version v1 = new Version(InternetVersion);
Version v2 = new Version(AssemblyVersion);
if (v1.CompareTo(v2) > 0)
MessageBox.Show(string.Format("New version {0} found!", result), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("You have the latest version!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (WebException)
{
MessageBox.Show("Could not download version information from GitHub.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception)
{
MessageBox.Show("Error processing version information.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@@ -30,48 +30,33 @@
{
this.btnClose = new System.Windows.Forms.Button();
this.pgConfig = new System.Windows.Forms.PropertyGrid();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnClose
//
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnClose.Location = new System.Drawing.Point(337, 427);
this.btnClose.Margin = new System.Windows.Forms.Padding(4);
this.btnClose.Location = new System.Drawing.Point(253, 347);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(100, 28);
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 0;
this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true;
//
// pgConfig
//
this.pgConfig.Location = new System.Drawing.Point(16, 15);
this.pgConfig.Margin = new System.Windows.Forms.Padding(4);
this.pgConfig.Location = new System.Drawing.Point(12, 12);
this.pgConfig.Name = "pgConfig";
this.pgConfig.Size = new System.Drawing.Size(421, 405);
this.pgConfig.Size = new System.Drawing.Size(316, 329);
this.pgConfig.TabIndex = 1;
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(229, 427);
this.btnCancel.Margin = new System.Windows.Forms.Padding(4);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(100, 28);
this.btnCancel.TabIndex = 0;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
//
// ConfigDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(449, 470);
this.ClientSize = new System.Drawing.Size(337, 382);
this.Controls.Add(this.pgConfig);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnClose);
this.Margin = new System.Windows.Forms.Padding(4);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "ConfigDialog";
this.Text = "Configuration Dialog";
this.ResumeLayout(false);
@@ -82,6 +67,5 @@
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.PropertyGrid pgConfig;
private System.Windows.Forms.Button btnCancel;
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Windows.Forms;
using System.Windows.Forms;
using vCardEditor.Repository;
using vCardEditor.Model;
namespace vCardEditor.View
{
@@ -10,7 +8,7 @@ namespace vCardEditor.View
public ConfigDialog()
{
InitializeComponent();
ConfigRepository conf = ConfigRepository.Instance;//
ConfigRepository conf = ConfigRepository.Instance;
pgConfig.SelectedObject = conf;
}
}

View File

@@ -36,8 +36,8 @@ namespace vCardEditor.View.Customs
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.cbInternational = new System.Windows.Forms.CheckBox();
this.cbCustom = new System.Windows.Forms.CheckBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.cbParcel = new System.Windows.Forms.CheckBox();
this.cbPreferred = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// cbHome
@@ -73,7 +73,7 @@ namespace vCardEditor.View.Customs
// cbDomestic
//
this.cbDomestic.AutoSize = true;
this.cbDomestic.Location = new System.Drawing.Point(12, 94);
this.cbDomestic.Location = new System.Drawing.Point(143, 40);
this.cbDomestic.Name = "cbDomestic";
this.cbDomestic.Size = new System.Drawing.Size(88, 21);
this.cbDomestic.TabIndex = 3;
@@ -82,8 +82,9 @@ namespace vCardEditor.View.Customs
//
// btnOK
//
this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point(95, 187);
this.btnOK.Location = new System.Drawing.Point(95, 161);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 7;
@@ -93,9 +94,10 @@ namespace vCardEditor.View.Customs
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.CausesValidation = false;
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(176, 187);
this.btnCancel.Location = new System.Drawing.Point(176, 161);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 8;
@@ -105,37 +107,41 @@ namespace vCardEditor.View.Customs
// cbInternational
//
this.cbInternational.AutoSize = true;
this.cbInternational.Location = new System.Drawing.Point(12, 121);
this.cbInternational.Location = new System.Drawing.Point(143, 12);
this.cbInternational.Name = "cbInternational";
this.cbInternational.Size = new System.Drawing.Size(108, 21);
this.cbInternational.TabIndex = 9;
this.cbInternational.Text = "International";
this.cbInternational.UseVisualStyleBackColor = true;
//
// cbCustom
// cbParcel
//
this.cbCustom.AutoSize = true;
this.cbCustom.Location = new System.Drawing.Point(12, 148);
this.cbCustom.Name = "cbCustom";
this.cbCustom.Size = new System.Drawing.Size(81, 21);
this.cbCustom.TabIndex = 10;
this.cbCustom.Text = "Custom:";
this.cbCustom.UseVisualStyleBackColor = true;
this.cbParcel.AutoSize = true;
this.cbParcel.Location = new System.Drawing.Point(143, 67);
this.cbParcel.Name = "cbParcel";
this.cbParcel.Size = new System.Drawing.Size(70, 21);
this.cbParcel.TabIndex = 10;
this.cbParcel.Text = "Parcel";
this.cbParcel.UseVisualStyleBackColor = true;
//
// textBox1
// cbPreferred
//
this.textBox1.Location = new System.Drawing.Point(90, 149);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(161, 22);
this.textBox1.TabIndex = 11;
this.cbPreferred.AutoSize = true;
this.cbPreferred.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cbPreferred.Location = new System.Drawing.Point(95, 113);
this.cbPreferred.Name = "cbPreferred";
this.cbPreferred.Size = new System.Drawing.Size(99, 21);
this.cbPreferred.TabIndex = 11;
this.cbPreferred.Text = "Preferred";
this.cbPreferred.UseVisualStyleBackColor = true;
//
// AddAddress
// AddAddressDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(263, 223);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.cbCustom);
this.ClientSize = new System.Drawing.Size(263, 196);
this.Controls.Add(this.cbPreferred);
this.Controls.Add(this.cbParcel);
this.Controls.Add(this.cbInternational);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
@@ -143,7 +149,7 @@ namespace vCardEditor.View.Customs
this.Controls.Add(this.cbPostal);
this.Controls.Add(this.cbWork);
this.Controls.Add(this.cbHome);
this.Name = "AddAddress";
this.Name = "AddAddressDialog";
this.Text = "Address Type";
this.ResumeLayout(false);
this.PerformLayout();
@@ -159,7 +165,7 @@ namespace vCardEditor.View.Customs
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.CheckBox cbInternational;
private System.Windows.Forms.CheckBox cbCustom;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.CheckBox cbParcel;
private System.Windows.Forms.CheckBox cbPreferred;
}
}

View File

@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Thought.vCards;
@@ -30,57 +26,52 @@ namespace vCardEditor.View.Customs
Addresses = addressCollection;
_checkBoxes = Controls.OfType<CheckBox>().ToList();
foreach (var item in addressCollection)
foreach (vCardDeliveryAddressTypes item in addressCollection)
{
switch (item.ToString())
{
case "Home":
cbHome.Checked = true;
break;
break;
case "Work":
cbWork.Checked = true;
break;
case "Postal":
cbPostal.Checked = true;
break;
case "Parcel":
cbParcel.Checked = true;
break;
case "Preferred":
cbPreferred.Checked = true;
break;
case "Domestic":
cbDomestic.Checked = true;
break;
case "International":
cbInternational.Checked = true;
break;
case "Default":
cbCustom.Checked = true;
break;
}
}
}
private void btnOK_Click(object sender, EventArgs e)
{
var total = _checkBoxes
.Where(checkBox => checkBox.Checked);
var checkedItems = _checkBoxes.Where(checkBox => checkBox.Checked);
if (total.Count() == 0)
if (checkedItems.Count() == 0)
{
MessageBox.Show("One item must be checked!");
MessageBox.Show("At least, one address type must be checked!");
DialogResult = DialogResult.None;
return;
}
foreach (var item in total)
Addresses.Clear();
foreach (CheckBox item in checkedItems)
{
var enumType = (vCardDeliveryAddressTypes)Enum.Parse(typeof(vCardDeliveryAddressTypes), item.Text, true);
vCardDeliveryAddressTypes enumType = (vCardDeliveryAddressTypes)Enum.Parse(typeof(vCardDeliveryAddressTypes), item.Text, true);
Addresses.Add(enumType);
}
}
}
}

View File

@@ -29,38 +29,36 @@ namespace vCardEditor.View.Customs
/// </summary>
private void InitializeComponent()
{
this.ExtAddrValue = new vCardEditor.View.StateTextBox();
this.ExtAddrValue = new vCardEditor.View.Customs.StateTextBox();
this.ExtAdressLabel = new System.Windows.Forms.Label();
this.StreetLabel = new System.Windows.Forms.Label();
this.StreetValue = new vCardEditor.View.StateTextBox();
this.StreetValue = new vCardEditor.View.Customs.StateTextBox();
this.POBoxLabel = new System.Windows.Forms.Label();
this.CountryValue = new vCardEditor.View.StateTextBox();
this.CountryValue = new vCardEditor.View.Customs.StateTextBox();
this.Country = new System.Windows.Forms.Label();
this.POBoxValue = new vCardEditor.View.StateTextBox();
this.POBoxValue = new vCardEditor.View.Customs.StateTextBox();
this.CityLabel = new System.Windows.Forms.Label();
this.RegionValue = new vCardEditor.View.StateTextBox();
this.CityValue = new vCardEditor.View.StateTextBox();
this.RegionValue = new vCardEditor.View.Customs.StateTextBox();
this.CityValue = new vCardEditor.View.Customs.StateTextBox();
this.StateLabel = new System.Windows.Forms.Label();
this.ZipLabel = new System.Windows.Forms.Label();
this.ZipValue = new vCardEditor.View.StateTextBox();
this.ZipValue = new vCardEditor.View.Customs.StateTextBox();
this.SuspendLayout();
//
// ExtAddrValue
//
this.ExtAddrValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ExtAddrValue.Location = new System.Drawing.Point(90, 45);
this.ExtAddrValue.Location = new System.Drawing.Point(68, 45);
this.ExtAddrValue.Margin = new System.Windows.Forms.Padding(4);
this.ExtAddrValue.Name = "ExtAddrValue";
this.ExtAddrValue.oldText = null;
this.ExtAddrValue.Size = new System.Drawing.Size(237, 22);
this.ExtAddrValue.Size = new System.Drawing.Size(190, 22);
this.ExtAddrValue.TabIndex = 27;
this.ExtAddrValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.ExtAddrValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// ExtAdressLabel
//
this.ExtAdressLabel.Location = new System.Drawing.Point(4, 45);
this.ExtAdressLabel.Location = new System.Drawing.Point(5, 44);
this.ExtAdressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.ExtAdressLabel.Name = "ExtAdressLabel";
this.ExtAdressLabel.Size = new System.Drawing.Size(40, 23);
@@ -73,7 +71,7 @@ namespace vCardEditor.View.Customs
this.StreetLabel.Location = new System.Drawing.Point(2, 14);
this.StreetLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.StreetLabel.Name = "StreetLabel";
this.StreetLabel.Size = new System.Drawing.Size(65, 23);
this.StreetLabel.Size = new System.Drawing.Size(64, 23);
this.StreetLabel.TabIndex = 14;
this.StreetLabel.Text = "Address:";
this.StreetLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
@@ -82,18 +80,18 @@ namespace vCardEditor.View.Customs
//
this.StreetValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.StreetValue.Location = new System.Drawing.Point(90, 14);
this.StreetValue.Location = new System.Drawing.Point(68, 14);
this.StreetValue.Margin = new System.Windows.Forms.Padding(4);
this.StreetValue.Name = "StreetValue";
this.StreetValue.oldText = "";
this.StreetValue.Size = new System.Drawing.Size(613, 22);
this.StreetValue.Size = new System.Drawing.Size(632, 22);
this.StreetValue.TabIndex = 15;
this.StreetValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.StreetValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// POBoxLabel
//
this.POBoxLabel.Location = new System.Drawing.Point(338, 75);
this.POBoxLabel.Location = new System.Drawing.Point(267, 76);
this.POBoxLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.POBoxLabel.Name = "POBoxLabel";
this.POBoxLabel.Size = new System.Drawing.Size(38, 23);
@@ -105,18 +103,18 @@ namespace vCardEditor.View.Customs
//
this.CountryValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CountryValue.Location = new System.Drawing.Point(579, 76);
this.CountryValue.Location = new System.Drawing.Point(557, 76);
this.CountryValue.Margin = new System.Windows.Forms.Padding(4);
this.CountryValue.Name = "CountryValue";
this.CountryValue.oldText = null;
this.CountryValue.Size = new System.Drawing.Size(125, 22);
this.CountryValue.Size = new System.Drawing.Size(143, 22);
this.CountryValue.TabIndex = 25;
this.CountryValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.CountryValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// Country
//
this.Country.Location = new System.Drawing.Point(505, 76);
this.Country.Location = new System.Drawing.Point(486, 74);
this.Country.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.Country.Name = "Country";
this.Country.Size = new System.Drawing.Size(65, 23);
@@ -126,20 +124,18 @@ namespace vCardEditor.View.Customs
//
// POBoxValue
//
this.POBoxValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.POBoxValue.Location = new System.Drawing.Point(397, 76);
this.POBoxValue.Location = new System.Drawing.Point(315, 77);
this.POBoxValue.Margin = new System.Windows.Forms.Padding(4);
this.POBoxValue.Name = "POBoxValue";
this.POBoxValue.oldText = null;
this.POBoxValue.Size = new System.Drawing.Size(100, 22);
this.POBoxValue.Size = new System.Drawing.Size(166, 22);
this.POBoxValue.TabIndex = 17;
this.POBoxValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.POBoxValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// CityLabel
//
this.CityLabel.Location = new System.Drawing.Point(338, 46);
this.CityLabel.Location = new System.Drawing.Point(267, 44);
this.CityLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.CityLabel.Name = "CityLabel";
this.CityLabel.Size = new System.Drawing.Size(32, 23);
@@ -151,31 +147,29 @@ namespace vCardEditor.View.Customs
//
this.RegionValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.RegionValue.Location = new System.Drawing.Point(90, 75);
this.RegionValue.Location = new System.Drawing.Point(557, 44);
this.RegionValue.Margin = new System.Windows.Forms.Padding(4);
this.RegionValue.Name = "RegionValue";
this.RegionValue.oldText = null;
this.RegionValue.Size = new System.Drawing.Size(236, 22);
this.RegionValue.Size = new System.Drawing.Size(143, 22);
this.RegionValue.TabIndex = 23;
this.RegionValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.RegionValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// CityValue
//
this.CityValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.CityValue.Location = new System.Drawing.Point(397, 45);
this.CityValue.Location = new System.Drawing.Point(316, 46);
this.CityValue.Margin = new System.Windows.Forms.Padding(4);
this.CityValue.Name = "CityValue";
this.CityValue.oldText = null;
this.CityValue.Size = new System.Drawing.Size(127, 22);
this.CityValue.Size = new System.Drawing.Size(166, 22);
this.CityValue.TabIndex = 19;
this.CityValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.CityValue.Validated += new System.EventHandler(this.Value_TextChanged);
//
// StateLabel
//
this.StateLabel.Location = new System.Drawing.Point(2, 74);
this.StateLabel.Location = new System.Drawing.Point(486, 46);
this.StateLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.StateLabel.Name = "StateLabel";
this.StateLabel.Size = new System.Drawing.Size(61, 23);
@@ -185,31 +179,29 @@ namespace vCardEditor.View.Customs
//
// ZipLabel
//
this.ZipLabel.Location = new System.Drawing.Point(533, 45);
this.ZipLabel.Location = new System.Drawing.Point(5, 75);
this.ZipLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.ZipLabel.Name = "ZipLabel";
this.ZipLabel.Size = new System.Drawing.Size(37, 23);
this.ZipLabel.TabIndex = 20;
this.ZipLabel.TabIndex = 28;
this.ZipLabel.Text = "Zip:";
this.ZipLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// ZipValue
//
this.ZipValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ZipValue.Location = new System.Drawing.Point(579, 46);
this.ZipValue.Location = new System.Drawing.Point(68, 77);
this.ZipValue.Margin = new System.Windows.Forms.Padding(4);
this.ZipValue.Name = "ZipValue";
this.ZipValue.oldText = null;
this.ZipValue.Size = new System.Drawing.Size(124, 22);
this.ZipValue.TabIndex = 21;
this.ZipValue.LostFocus += new System.EventHandler(this.Value_TextChanged);
this.ZipValue.Validated += new System.EventHandler(this.Value_TextChanged);
this.ZipValue.Size = new System.Drawing.Size(190, 22);
this.ZipValue.TabIndex = 29;
//
// AddressBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.ZipLabel);
this.Controls.Add(this.ZipValue);
this.Controls.Add(this.ExtAddrValue);
this.Controls.Add(this.ExtAdressLabel);
this.Controls.Add(this.StreetLabel);
@@ -222,8 +214,6 @@ namespace vCardEditor.View.Customs
this.Controls.Add(this.RegionValue);
this.Controls.Add(this.CityValue);
this.Controls.Add(this.StateLabel);
this.Controls.Add(this.ZipLabel);
this.Controls.Add(this.ZipValue);
this.Name = "AddressBox";
this.Size = new System.Drawing.Size(706, 104);
this.ResumeLayout(false);

View File

@@ -8,8 +8,8 @@ namespace vCardEditor.View.Customs
public partial class AddressBox : UserControl
{
public event EventHandler TextChangedEvent;
public List<vCardDeliveryAddressTypes> AddressType { get; set; }
public AddressBox(string street, string city, string region, string country, string postalCode,
string extendedAddress, string postOfficeBox, List<vCardDeliveryAddressTypes> addressType)
@@ -46,7 +46,7 @@ namespace vCardEditor.View.Customs
public vCardDeliveryAddress getDeliveryAddress()
{
var deliveryAddress = new vCardDeliveryAddress
vCardDeliveryAddress deliveryAddress = new vCardDeliveryAddress
{
City = CityValue.Text,
Country = CountryValue.Text,
@@ -57,9 +57,7 @@ namespace vCardEditor.View.Customs
PostOfficeBox = POBoxValue.Text,
AddressType = AddressType
};
return deliveryAddress;
}
}
}

View File

@@ -26,7 +26,6 @@ namespace vCardEditor.View.Customs
Selecting += tbcAddress_Selecting;
HandleCreated += tbcAddress_HandleCreated;
MouseDoubleClick += AddressTabControl_MouseDoubleClick;
}
public void getDeliveryAddress(vCard card)
@@ -51,9 +50,9 @@ namespace vCardEditor.View.Customs
{
if (GetTabRect(i).Contains(e.Location))
{
var AddressBox = TabPages[i].Controls[0] as AddressBox;
AddressBox AddressBox = TabPages[i].Controls[0] as AddressBox;
var diag = new AddAddressDialog(AddressBox.AddressType);
AddAddressDialog diag = new AddAddressDialog(AddressBox.AddressType);
if (diag.ShowDialog() == DialogResult.OK)
{
@@ -66,10 +65,8 @@ namespace vCardEditor.View.Customs
break;
}
}
}
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
private const int TCM_SETMINTABWIDTH = 0x1300 + 49;
@@ -78,38 +75,35 @@ namespace vCardEditor.View.Customs
SendMessage(Handle, TCM_SETMINTABWIDTH, IntPtr.Zero, (IntPtr)16);
}
private void tbcAddress_Selecting(object sender, TabControlCancelEventArgs e)
{
if (e.TabPageIndex == TabCount - 1)
e.Cancel = true;
}
private void tbcAddress_MouseDown(object sender, MouseEventArgs e)
{
var lastIndex = TabCount - 1;
int lastIndex = TabCount - 1;
if (GetTabRect(lastIndex).Contains(e.Location))
{
var diag = new AddAddressDialog();
AddAddressDialog diag = new AddAddressDialog();
if (diag.ShowDialog() == DialogResult.OK)
{
vCardDeliveryAddress da = new vCardDeliveryAddress();
da.AddressType = diag.Addresses;
AddtabForAddress(da);
AddTab?.Invoke(sender, new EventArg<List<vCardDeliveryAddressTypes>>(diag.Addresses));
SelectedIndex = TabCount - 1;
SelectedIndex = TabCount - 2;
}
}
else
{
for (var i = 0; i < TabPages.Count; i++)
for (int i = 0; i < TabPages.Count; i++)
{
var tabRect = GetTabRect(i);
Rectangle tabRect = GetTabRect(i);
tabRect.Inflate(-2, -2);
var closeImage = Properties.Resources.Close;
var imageRect = new Rectangle(
Bitmap closeImage = Properties.Resources.Close;
Rectangle imageRect = new Rectangle(
(tabRect.Right - closeImage.Width),
tabRect.Top + (tabRect.Height - closeImage.Height) / 2,
closeImage.Width, closeImage.Height);
@@ -122,12 +116,9 @@ namespace vCardEditor.View.Customs
SelectedIndex = 0;
RemoveTab?.Invoke(sender, new EventArg<int>(i));
}
return;
}
}
}
}
@@ -136,19 +127,19 @@ namespace vCardEditor.View.Customs
if (e.Index > TabCount - 1)
return;
var tabRect = GetTabRect(e.Index);
Rectangle tabRect = GetTabRect(e.Index);
tabRect.Inflate(-2, -2);
if (e.Index == TabCount - 1)
{
var addImage = Properties.Resources.Add;
Bitmap addImage = Properties.Resources.Add;
e.Graphics.DrawImage(addImage,
tabRect.Left + (tabRect.Width - addImage.Width) / 2,
tabRect.Top + (tabRect.Height - addImage.Height) / 2);
}
else
{
var closeImage = Properties.Resources.Close;
Bitmap closeImage = Properties.Resources.Close;
e.Graphics.DrawImage(closeImage,
(tabRect.Right - closeImage.Width),
tabRect.Top + (tabRect.Height - closeImage.Height) / 2);
@@ -172,8 +163,6 @@ namespace vCardEditor.View.Customs
TextBrush.Dispose();
}
}
public void SetAddresses(vCard card)
@@ -184,7 +173,7 @@ namespace vCardEditor.View.Customs
private void AddTabForEveryAddress(vCard card)
{
foreach (var item in card.DeliveryAddresses)
foreach (vCardDeliveryAddress item in card.DeliveryAddresses)
AddtabForAddress(item);
SelectedIndex = 0;
}
@@ -193,35 +182,32 @@ namespace vCardEditor.View.Customs
{
string title = GetTabTitle(da.AddressType);
var page = new TabPage($" {title} ");
TabPage page = new TabPage($" {title} ");
TabPages.Insert(TabCount - 1, page);
var ab = new AddressBox(da.Street, da.City, da.Region, da.Country,
AddressBox ab = new AddressBox(da.Street, da.City, da.Region, da.Country,
da.PostalCode, da.ExtendedAddress, da.PostOfficeBox, da.AddressType);
ab.TextChangedEvent += (s, e) => TextChangedEvent?.Invoke(s, e);
ab.Dock = DockStyle.Fill;
page.Controls.Add(ab);
page.ToolTipText = string.Join(",", da.AddressType.ConvertAll(f => f.ToString()));
}
private string GetTabTitle(List<vCardDeliveryAddressTypes> addressTypes)
{
var title = string.Empty;
string title = string.Empty;
if (addressTypes.Count > 0)
{
title = addressTypes[0].ToString();
if (addressTypes.Count > 1)
title += "...";
}
return title;
}
private void ClearTabs()
{
//Remove every tab (except "+"). We don't call Clear() as it doesn't free memory.
while (TabCount > 1)
TabPages[0].Dispose();

View File

@@ -18,7 +18,7 @@ namespace vCardEditor.View.Customs
_checkBoxes = Controls.OfType<CheckBox>().ToList();
Columns = columns;
foreach (var item in columns)
foreach (Column item in columns)
{
switch (item)
{
@@ -36,13 +36,9 @@ namespace vCardEditor.View.Customs
private void btnOK_Click(object sender, EventArgs e)
{
Columns.Clear();
var total = _checkBoxes
.Where(checkBox => checkBox.Checked);
foreach (var item in total)
foreach (CheckBox item in _checkBoxes.Where(checkBox => checkBox.Checked))
{
var enumType = (Column)Enum.Parse(typeof(Column), item.Text, true);
Column enumType = (Column)Enum.Parse(typeof(Column), item.Text, true);
Columns.Add(enumType);
}
}

View File

@@ -1,7 +1,7 @@

namespace vCardEditor.View.Customs
{
partial class CustumInputDialog
partial class CustomInputDialog
{
/// <summary>
/// Required designer variable.

View File

@@ -2,9 +2,9 @@
namespace vCardEditor.View.Customs
{
public partial class CustumInputDialog : Form
public partial class CustomInputDialog : Form
{
public CustumInputDialog()
public CustomInputDialog()
{
InitializeComponent();
}
@@ -15,7 +15,5 @@ namespace vCardEditor.View.Customs
{
input = tbInput.Text;
}
}
}

View File

@@ -6,30 +6,19 @@ using Thought.vCards;
namespace vCardEditor.View.Customs
{
public partial class ExtendedPanel : UserControl
{
public event EventHandler ContentTextChanged;
public string Caption
{
get { return PanelContent.Text; }
set { PanelContent.Text = value; }
}
public PanelType panelType { get; set; }
public ExtendedPanel(PanelType _panel)
public ExtendedPanel()
{
InitializeComponent();
panelType = _panel;
miCell.Click += MenuItemClickHandlers;
miCell.Tag = new vCardPhone(string.Empty, vCardPhoneTypes.Cellular);
miCell.Click += MenuItemClickHandlers;
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);
@@ -45,17 +34,26 @@ namespace vCardEditor.View.Customs
//{
// AddControl(custom.input, string.Empty);
//}
}
public event EventHandler ContentTextChanged;
public event EventHandler CardInfoRemoved;
public string Caption
{
get { return PanelContent.Text; }
set { PanelContent.Text = value; }
}
public PanelType panelType { get; set; }
private void MenuItemClickHandlers(object sender, EventArgs e)
{
var tag = (sender as ToolStripMenuItem).Tag;
object tag = (sender as ToolStripMenuItem).Tag;
if (tag != null && tag is vCardRoot)
AddControl(tag as vCardRoot);
}
private void btnAddExtraText_Click(object sender, EventArgs e)
{
Button btnSender = (Button)sender;
@@ -73,35 +71,31 @@ namespace vCardEditor.View.Customs
default:
break;
}
}
public void AddControl(vCardRoot card)
{
Point pt = GetCoordinatesForNewControl();
RemovableTextBox ctl = new RemovableTextBox(card);
ctl.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;
ctl.Location = pt;
ctl.Width = PanelContent.Width - 20; //TODO : Calculte the right size of the scrollbar!
RemovableTextBox ctl = new RemovableTextBox(card)
{
Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left,
Location = pt,
Width = PanelContent.Width - 20 //TODO : Calculte the right size of the scrollbar!
};
ctl.BoutonRemoveClicked += RemoveControl;
ctl.ButtonRemoveClicked += RemoveControl;
ctl.ContentTextChanged += (s, e) => ContentTextChanged?.Invoke(s, e);
PanelContent.Controls.Add(ctl);
}
public List<vCardRoot> GetExtraFields()
{
List<vCardRoot> result = new List<vCardRoot>();
foreach (var item in PanelContent.Controls)
foreach (Control item in PanelContent.Controls)
{
var ctl = item as RemovableTextBox;
result.Add(ctl.Tag as vCardRoot);
result.Add((item as RemovableTextBox).Tag as vCardRoot);
}
return result;
@@ -115,40 +109,28 @@ namespace vCardEditor.View.Customs
private void RemoveControl(object sender, EventArgs e)
{
var par = (sender as Control).Parent;
PanelContent.Controls.Remove(par);
ReplaceControls();
}
private void ReplaceControls()
{
for (int i = 0; i < PanelContent.Controls.Count; i++)
if (MessageBox.Show("Are you sure?", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
var ctl = PanelContent.Controls[i];
ctl.Location = new Point(5, (i * 30) + 10);
PanelContent.Controls.Remove((sender as Control).Parent);
for (int i = 0; i < PanelContent.Controls.Count; i++)
{
PanelContent.Controls[i].Location = new Point(5, (i * 30) + 10);
}
CardInfoRemoved?.Invoke(sender, e);
}
}
private Point GetCoordinatesForNewControl()
{
Point pt;
if (PanelContent.Controls.Count > 0)
{
var LastControl = PanelContent.Controls[PanelContent.Controls.Count - 1];
pt = LastControl.Location;
pt = PanelContent.Controls[PanelContent.Controls.Count - 1].Location;
pt.Y += 30;
}
else
pt = new Point(5, 10);
return pt;
}
}
}

View File

@@ -30,7 +30,7 @@ namespace vCardEditor.View.UIToolbox
private void InitializeComponent()
{
this.btnClose = new System.Windows.Forms.Button();
this.txtContent = new vCardEditor.View.StateTextBox();
this.txtContent = new vCardEditor.View.Customs.StateTextBox();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
@@ -47,6 +47,8 @@ namespace vCardEditor.View.UIToolbox
//
// txtContent
//
this.txtContent.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtContent.Location = new System.Drawing.Point(56, 4);
this.txtContent.Multiline = true;
this.txtContent.Name = "txtContent";
@@ -76,7 +78,7 @@ namespace vCardEditor.View.UIToolbox
#endregion
private System.Windows.Forms.Button btnClose;
private StateTextBox txtContent;
private Customs.StateTextBox txtContent;
private System.Windows.Forms.Label label2;
}
}

View File

@@ -31,7 +31,7 @@ namespace vCardEditor.View.Customs
{
this.btnRemove = new System.Windows.Forms.Button();
this.TitleLabel = new System.Windows.Forms.Label();
this.ContentTextBox = new vCardEditor.View.StateTextBox();
this.ContentTextBox = new vCardEditor.View.Customs.StateTextBox();
this.SuspendLayout();
//
// btnRemove

View File

@@ -6,12 +6,13 @@ namespace vCardEditor.View.Customs
{
public partial class RemovableTextBox : UserControl
{
public event EventHandler BoutonRemoveClicked;
public event EventHandler ButtonRemoveClicked;
public event EventHandler ContentTextChanged;
public RemovableTextBox()
{
InitializeComponent();
btnRemove.Click += (s, e) => BoutonRemoveClicked?.Invoke(s, e);
btnRemove.Click += (s, e) => ButtonRemoveClicked?.Invoke(s, e);
// Bubble up to set the dirty flag from the parent.
ContentTextBox.LostFocus += (s, e) => ContentTextChanged?.Invoke(s, e);
ContentTextBox.Validated += (s, e) => ContentTextChanged?.Invoke(s, e);
@@ -22,7 +23,7 @@ namespace vCardEditor.View.Customs
private void ContentTextBox_Validated(object sender, EventArgs e)
{
var card = this.Tag as vCardRoot;
vCardRoot card = this.Tag as vCardRoot;
card.ChangeContent(Content);
}
@@ -33,7 +34,6 @@ namespace vCardEditor.View.Customs
Content = cardType.ToString();
}
public string Title
{
get { return TitleLabel.Text; }
@@ -45,6 +45,5 @@ namespace vCardEditor.View.Customs
get { return ContentTextBox.Text; }
set { ContentTextBox.Text = value; }
}
}
}

View File

@@ -1,7 +1,7 @@
using System;
using System.Windows.Forms;
namespace vCardEditor.View
namespace vCardEditor.View.Customs
{
public class StateTextBox : TextBox
{
@@ -9,8 +9,8 @@ namespace vCardEditor.View
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
oldText = this.Text;
base.OnLostFocus(e);
}
}

View File

@@ -12,5 +12,7 @@ namespace VCFEditor.View
}
public T Data { get; set; }
public bool CanCancel { get; set; }
}
}

View File

@@ -27,14 +27,21 @@ namespace VCFEditor.View
event EventHandler<EventArg<int>> AddressRemoved;
event EventHandler CopyTextToClipboardEvent;
event EventHandler<EventArg<vCardPropeties>> AddExtraField;
event EventHandler CountImagesEvent;
event EventHandler ClearImagesEvent;
event EventHandler BatchExportImagesEvent;
event EventHandler<EventArg<string>> OpenFolderEvent;
event EventHandler SplitFileEvent;
event EventHandler CardInfoRemoved;
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 DisplaySaveDialog(string filename);
string DisplayOpenFileDialog(string filter);
string DisplaySaveDialog();
void UpdateMRUMenu(FixedList MRUList);
void SendTextToClipBoard(string text);
@@ -43,5 +50,10 @@ namespace VCFEditor.View
void LoadIntialState(FormState state);
void AddExtraTextGroup(vCardPropeties type, string content);
void DisplayQRCode(string content);
void ClearImageFromForm();
string DisplayOpenFolderDialog();
void LoadLocalizedUI(IReadOnlyDictionary<string, string> currentMessages);
void LoadAvailablesLangs(IEnumerable<string> availableLanguages);
}
}

View File

@@ -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();
@@ -78,19 +78,19 @@ namespace vCardEditor.View
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tcMainTab = new System.Windows.Forms.TabControl();
this.TapPageMain = new System.Windows.Forms.TabPage();
this.extendedPanelWeb = new vCardEditor.View.Customs.ExtendedPanel(PanelType.Web);
this.extendedPanelPhones = new vCardEditor.View.Customs.ExtendedPanel(PanelType.Phone);
this.extendedPanelWeb = new vCardEditor.View.Customs.ExtendedPanel();
this.extendedPanelPhones = new vCardEditor.View.Customs.ExtendedPanel();
this.btnExportImage = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.FormattedTitleValue = new vCardEditor.View.StateTextBox();
this.FormattedTitleValue = new vCardEditor.View.Customs.StateTextBox();
this.FormattedTitleLabel = new System.Windows.Forms.Label();
this.lastNameValue = new vCardEditor.View.StateTextBox();
this.lastNameValue = new vCardEditor.View.Customs.StateTextBox();
this.label3 = new System.Windows.Forms.Label();
this.middleNameValue = new vCardEditor.View.StateTextBox();
this.middleNameValue = new vCardEditor.View.Customs.StateTextBox();
this.label2 = new System.Windows.Forms.Label();
this.firstNameValue = new vCardEditor.View.StateTextBox();
this.firstNameValue = new vCardEditor.View.Customs.StateTextBox();
this.label1 = new System.Windows.Forms.Label();
this.FormattedNameValue = new vCardEditor.View.StateTextBox();
this.FormattedNameValue = new vCardEditor.View.Customs.StateTextBox();
this.FormattedNameLabel = new System.Windows.Forms.Label();
this.btnRemoveImage = new System.Windows.Forms.Button();
this.groupBox4 = new System.Windows.Forms.GroupBox();
@@ -98,7 +98,14 @@ namespace vCardEditor.View
this.tabPage3 = new System.Windows.Forms.TabPage();
this.PhotoBox = new System.Windows.Forms.PictureBox();
this.TapPageExtra = new System.Windows.Forms.TabPage();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnAddExtraText = new System.Windows.Forms.Button();
this.panelTabExtra = new System.Windows.Forms.Panel();
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();
@@ -116,6 +123,8 @@ namespace vCardEditor.View
this.tbcAddress.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PhotoBox)).BeginInit();
this.TapPageExtra.SuspendLayout();
this.groupBox1.SuspendLayout();
this.menuExtraField.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
@@ -128,7 +137,7 @@ namespace vCardEditor.View
this.helpToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1202, 30);
this.menuStrip1.Size = new System.Drawing.Size(1202, 28);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
@@ -142,7 +151,7 @@ namespace vCardEditor.View
this.recentFilesMenuItem,
this.miQuit});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 26);
this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24);
this.fileToolStripMenuItem.Text = "File";
//
// miSave
@@ -193,7 +202,7 @@ namespace vCardEditor.View
this.copyToolStripMenuItem,
this.extraFieldsToolStripMenuItem});
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(49, 26);
this.editToolStripMenuItem.Size = new System.Drawing.Size(49, 24);
this.editToolStripMenuItem.Text = "Edit";
//
// copyToolStripMenuItem
@@ -231,7 +240,7 @@ namespace vCardEditor.View
this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.imagesToolStripMenuItem});
this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem";
this.toolsToolStripMenuItem.Size = new System.Drawing.Size(58, 26);
this.toolsToolStripMenuItem.Size = new System.Drawing.Size(58, 24);
this.toolsToolStripMenuItem.Text = "Tools";
//
// imagesToolStripMenuItem
@@ -249,25 +258,28 @@ namespace vCardEditor.View
this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
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(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(135, 26);
this.countToolStripMenuItem.Text = "Count";
this.countToolStripMenuItem.Click += new System.EventHandler(this.countToolStripMenuItem_Click);
//
// helpToolStripMenuItem
//
this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.miAbout});
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new System.Drawing.Size(55, 26);
this.helpToolStripMenuItem.Size = new System.Drawing.Size(55, 24);
this.helpToolStripMenuItem.Text = "Help";
//
// miAbout
@@ -301,9 +313,9 @@ namespace vCardEditor.View
this.toolStripSeparator1,
this.tbsAbout,
this.toolStripSeparator});
this.toolStrip1.Location = new System.Drawing.Point(0, 30);
this.toolStrip1.Location = new System.Drawing.Point(0, 28);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(1202, 31);
this.toolStrip1.Size = new System.Drawing.Size(1202, 27);
this.toolStrip1.TabIndex = 1;
this.toolStrip1.Text = "toolStrip1";
//
@@ -313,29 +325,28 @@ namespace vCardEditor.View
this.tbsNew.Image = ((System.Drawing.Image)(resources.GetObject("tbsNew.Image")));
this.tbsNew.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbsNew.Name = "tbsNew";
this.tbsNew.Size = new System.Drawing.Size(29, 28);
this.tbsNew.Size = new System.Drawing.Size(29, 24);
this.tbsNew.Text = "&Nouveau";
this.tbsNew.Click += new System.EventHandler(this.tbsNew_Click);
//
// 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, 28);
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, 28);
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
//
@@ -343,7 +354,7 @@ namespace vCardEditor.View
this.tbsDelete.Image = ((System.Drawing.Image)(resources.GetObject("tbsDelete.Image")));
this.tbsDelete.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbsDelete.Name = "tbsDelete";
this.tbsDelete.Size = new System.Drawing.Size(29, 28);
this.tbsDelete.Size = new System.Drawing.Size(29, 24);
this.tbsDelete.Text = "Delete";
this.tbsDelete.Click += new System.EventHandler(this.tbsDelete_Click);
//
@@ -353,14 +364,14 @@ namespace vCardEditor.View
this.tbsQR.Image = global::vCardEditor.Properties.Resources.nuget_icon;
this.tbsQR.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbsQR.Name = "tbsQR";
this.tbsQR.Size = new System.Drawing.Size(29, 28);
this.tbsQR.Size = new System.Drawing.Size(29, 24);
this.tbsQR.Text = "&QR Code";
this.tbsQR.Click += new System.EventHandler(this.tbsQR_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 31);
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 27);
//
// tbsAbout
//
@@ -368,14 +379,14 @@ namespace vCardEditor.View
this.tbsAbout.Image = ((System.Drawing.Image)(resources.GetObject("tbsAbout.Image")));
this.tbsAbout.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbsAbout.Name = "tbsAbout";
this.tbsAbout.Size = new System.Drawing.Size(29, 28);
this.tbsAbout.Size = new System.Drawing.Size(29, 24);
this.tbsAbout.Text = "&?";
this.tbsAbout.Click += new System.EventHandler(this.tbsAbout_Click);
//
// toolStripSeparator
//
this.toolStripSeparator.Name = "toolStripSeparator";
this.toolStripSeparator.Size = new System.Drawing.Size(6, 31);
this.toolStripSeparator.Size = new System.Drawing.Size(6, 27);
//
// openFileDialog
//
@@ -392,7 +403,7 @@ namespace vCardEditor.View
this.gbNameList.Margin = new System.Windows.Forms.Padding(4);
this.gbNameList.Name = "gbNameList";
this.gbNameList.Padding = new System.Windows.Forms.Padding(4);
this.gbNameList.Size = new System.Drawing.Size(398, 580);
this.gbNameList.Size = new System.Drawing.Size(398, 586);
this.gbNameList.TabIndex = 2;
this.gbNameList.TabStop = false;
this.gbNameList.Text = "Name List :";
@@ -402,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)));
@@ -424,7 +435,7 @@ namespace vCardEditor.View
this.dgContacts.RowHeadersVisible = false;
this.dgContacts.RowHeadersWidth = 51;
this.dgContacts.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgContacts.Size = new System.Drawing.Size(390, 527);
this.dgContacts.Size = new System.Drawing.Size(390, 533);
this.dgContacts.TabIndex = 2;
this.dgContacts.CellContextMenuStripNeeded += new System.Windows.Forms.DataGridViewCellContextMenuStripNeededEventHandler(this.dgContacts_CellContextMenuStripNeeded);
this.dgContacts.RowLeave += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgContacts_RowLeave);
@@ -507,7 +518,7 @@ namespace vCardEditor.View
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 61);
this.splitContainer1.Location = new System.Drawing.Point(0, 55);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
@@ -517,7 +528,7 @@ namespace vCardEditor.View
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.tcMainTab);
this.splitContainer1.Size = new System.Drawing.Size(1202, 580);
this.splitContainer1.Size = new System.Drawing.Size(1202, 586);
this.splitContainer1.SplitterDistance = 398;
this.splitContainer1.TabIndex = 4;
//
@@ -530,7 +541,7 @@ namespace vCardEditor.View
this.tcMainTab.Location = new System.Drawing.Point(0, 0);
this.tcMainTab.Name = "tcMainTab";
this.tcMainTab.SelectedIndex = 0;
this.tcMainTab.Size = new System.Drawing.Size(800, 580);
this.tcMainTab.Size = new System.Drawing.Size(800, 586);
this.tcMainTab.TabIndex = 0;
//
// TapPageMain
@@ -546,29 +557,31 @@ namespace vCardEditor.View
this.TapPageMain.Location = new System.Drawing.Point(4, 25);
this.TapPageMain.Name = "TapPageMain";
this.TapPageMain.Padding = new System.Windows.Forms.Padding(3);
this.TapPageMain.Size = new System.Drawing.Size(792, 551);
this.TapPageMain.Size = new System.Drawing.Size(792, 557);
this.TapPageMain.TabIndex = 0;
this.TapPageMain.Text = "Main";
//
// extendedPanelWeb
//
this.extendedPanelWeb.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
this.extendedPanelWeb.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)));
this.extendedPanelWeb.Caption = "";
this.extendedPanelWeb.Location = new System.Drawing.Point(402, 383);
this.extendedPanelWeb.Location = new System.Drawing.Point(386, 389);
this.extendedPanelWeb.Name = "extendedPanelWeb";
this.extendedPanelWeb.panelType = vCardEditor.View.Customs.PanelType.Web;
this.extendedPanelWeb.Size = new System.Drawing.Size(381, 155);
this.extendedPanelWeb.Size = new System.Drawing.Size(397, 161);
this.extendedPanelWeb.TabIndex = 59;
//
// extendedPanelPhones
//
this.extendedPanelPhones.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.extendedPanelPhones.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.extendedPanelPhones.Caption = "";
this.extendedPanelPhones.Location = new System.Drawing.Point(13, 383);
this.extendedPanelPhones.Location = new System.Drawing.Point(13, 389);
this.extendedPanelPhones.Name = "extendedPanelPhones";
this.extendedPanelPhones.panelType = vCardEditor.View.Customs.PanelType.Phone;
this.extendedPanelPhones.Size = new System.Drawing.Size(367, 155);
this.extendedPanelPhones.Size = new System.Drawing.Size(367, 161);
this.extendedPanelPhones.TabIndex = 58;
//
// btnExportImage
@@ -581,6 +594,7 @@ namespace vCardEditor.View
this.btnExportImage.Size = new System.Drawing.Size(21, 23);
this.btnExportImage.TabIndex = 57;
this.btnExportImage.UseVisualStyleBackColor = true;
this.btnExportImage.Click += new System.EventHandler(this.btnExportImage_Click);
//
// groupBox3
//
@@ -724,18 +738,18 @@ namespace vCardEditor.View
this.btnRemoveImage.Size = new System.Drawing.Size(20, 23);
this.btnRemoveImage.TabIndex = 56;
this.btnRemoveImage.UseVisualStyleBackColor = true;
this.btnRemoveImage.Click += new System.EventHandler(this.btnRemoveImage_Click);
//
// groupBox4
//
this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox4.Controls.Add(this.tbcAddress);
this.groupBox4.Location = new System.Drawing.Point(13, 184);
this.groupBox4.Margin = new System.Windows.Forms.Padding(4);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Padding = new System.Windows.Forms.Padding(4);
this.groupBox4.Size = new System.Drawing.Size(770, 192);
this.groupBox4.Size = new System.Drawing.Size(770, 198);
this.groupBox4.TabIndex = 5;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Address:";
@@ -753,7 +767,7 @@ namespace vCardEditor.View
this.tbcAddress.Padding = new System.Drawing.Point(12, 4);
this.tbcAddress.SelectedIndex = 0;
this.tbcAddress.ShowToolTips = true;
this.tbcAddress.Size = new System.Drawing.Size(745, 154);
this.tbcAddress.Size = new System.Drawing.Size(745, 160);
this.tbcAddress.TabIndex = 0;
//
// tabPage3
@@ -762,7 +776,7 @@ namespace vCardEditor.View
this.tabPage3.Location = new System.Drawing.Point(4, 27);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
this.tabPage3.Size = new System.Drawing.Size(737, 123);
this.tabPage3.Size = new System.Drawing.Size(737, 129);
this.tabPage3.TabIndex = 0;
this.tabPage3.Text = " ";
//
@@ -778,11 +792,12 @@ namespace vCardEditor.View
this.PhotoBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.PhotoBox.TabIndex = 55;
this.PhotoBox.TabStop = false;
this.PhotoBox.Click += new System.EventHandler(this.PhotoBox_Click);
//
// TapPageExtra
//
this.TapPageExtra.BackColor = System.Drawing.SystemColors.Control;
this.TapPageExtra.Controls.Add(this.flowLayoutPanel1);
this.TapPageExtra.Controls.Add(this.groupBox1);
this.TapPageExtra.Location = new System.Drawing.Point(4, 25);
this.TapPageExtra.Name = "TapPageExtra";
this.TapPageExtra.Padding = new System.Windows.Forms.Padding(3);
@@ -790,15 +805,81 @@ namespace vCardEditor.View
this.TapPageExtra.TabIndex = 1;
this.TapPageExtra.Text = "Extra";
//
// flowLayoutPanel1
// groupBox1
//
this.flowLayoutPanel1.BackColor = System.Drawing.SystemColors.Control;
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 3);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(786, 551);
this.flowLayoutPanel1.TabIndex = 0;
this.groupBox1.Controls.Add(this.btnAddExtraText);
this.groupBox1.Controls.Add(this.panelTabExtra);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox1.Location = new System.Drawing.Point(3, 3);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(786, 551);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
//
// btnAddExtraText
//
this.btnAddExtraText.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnAddExtraText.BackColor = System.Drawing.SystemColors.Window;
this.btnAddExtraText.Image = global::vCardEditor.Properties.Resources.Add;
this.btnAddExtraText.Location = new System.Drawing.Point(732, 0);
this.btnAddExtraText.Name = "btnAddExtraText";
this.btnAddExtraText.Size = new System.Drawing.Size(39, 22);
this.btnAddExtraText.TabIndex = 59;
this.btnAddExtraText.UseVisualStyleBackColor = true;
this.btnAddExtraText.Click += new System.EventHandler(this.btnAddExtraText_Click);
//
// panelTabExtra
//
this.panelTabExtra.AutoScroll = true;
this.panelTabExtra.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelTabExtra.Location = new System.Drawing.Point(3, 18);
this.panelTabExtra.Name = "panelTabExtra";
this.panelTabExtra.Size = new System.Drawing.Size(780, 530);
this.panelTabExtra.TabIndex = 1;
this.panelTabExtra.ControlAdded += new System.Windows.Forms.ControlEventHandler(this.panelTabExtra_ControlAdded);
this.panelTabExtra.ControlRemoved += new System.Windows.Forms.ControlEventHandler(this.panelTabExtra_ControlRemoved);
//
// menuExtraField
//
this.menuExtraField.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuExtraField.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.miNote,
this.miOrg});
this.menuExtraField.Name = "contextMenuStrip1";
this.menuExtraField.Size = new System.Drawing.Size(164, 52);
//
// miNote
//
this.miNote.Name = "miNote";
this.miNote.Size = new System.Drawing.Size(163, 24);
this.miNote.Text = "Note";
this.miNote.Click += new System.EventHandler(this.miNote_Click);
//
// miOrg
//
this.miOrg.Name = "miOrg";
this.miOrg.Size = new System.Drawing.Size(163, 24);
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
//
@@ -840,6 +921,8 @@ namespace vCardEditor.View
this.tbcAddress.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.PhotoBox)).EndInit();
this.TapPageExtra.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.menuExtraField.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -856,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;
@@ -889,12 +970,9 @@ namespace vCardEditor.View
private System.Windows.Forms.TabControl tcMainTab;
private System.Windows.Forms.TabPage TapPageMain;
private System.Windows.Forms.TabPage TapPageExtra;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.ToolStripMenuItem extraFieldsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem addNotesToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem addOrgToolStripMenuItem;
private ExtendedPanel extendedPanelWeb;
private ExtendedPanel extendedPanelPhones;
private System.Windows.Forms.Button btnExportImage;
private System.Windows.Forms.GroupBox groupBox3;
internal StateTextBox FormattedTitleValue;
@@ -913,5 +991,17 @@ namespace vCardEditor.View
private System.Windows.Forms.TabPage tabPage3;
internal System.Windows.Forms.PictureBox PhotoBox;
private System.Windows.Forms.ToolStripButton tbsQR;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Panel panelTabExtra;
private System.Windows.Forms.Button btnAddExtraText;
private System.Windows.Forms.ContextMenuStrip menuExtraField;
private System.Windows.Forms.ToolStripMenuItem miNote;
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;
}
}

View File

@@ -1,16 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using VCFEditor.View;
using VCFEditor.Model;
using Thought.vCards;
using vCardEditor.Repository;
using vCardEditor.Model;
using System.Drawing;
using System.Collections.Generic;
using vCardEditor.Repository;
using vCardEditor.View.Customs;
using vCardEditor.View.UIToolbox;
using VCFEditor.Model;
using VCFEditor.View;
namespace vCardEditor.View
{
@@ -34,10 +34,17 @@ namespace vCardEditor.View
public event EventHandler ExportImage;
public event EventHandler ExportQR;
public event EventHandler CopyTextToClipboardEvent;
public event EventHandler CountImagesEvent;
public event EventHandler ClearImagesEvent;
public event EventHandler BatchExportImagesEvent;
public event EventHandler<EventArg<string>> OpenFolderEvent;
public event EventHandler SplitFileEvent;
public event EventHandler CardInfoRemoved;
ComponentResourceManager resources;
private int LastRowIndex = -1;
public int SelectedContactIndex
{
get
@@ -47,46 +54,65 @@ namespace vCardEditor.View
else
return -1;
}
}
public MainForm()
{
InitializeComponent();
resources = new ComponentResourceManager(typeof(MainForm));
tbcAddress.AddTab += (sender, e) => AddressAdded?.Invoke(sender, e);
tbcAddress.RemoveTab += (sender, e) => AddressRemoved?.Invoke(sender, e);
tbcAddress.ModifyTab += (sender, e) => AddressModified?.Invoke(sender, e);
tbcAddress.TextChangedEvent += (sender, e) => TextBoxValueChanged?.Invoke(sender, e);
btnClearFilter.Click += (sender, e) => textBoxFilter.Clear();
extendedPanelPhones.ContentTextChanged += (sender, e) => TextBoxValueChanged?.Invoke(sender, e);
extendedPanelWeb.ContentTextChanged += (sender, e) => TextBoxValueChanged?.Invoke(sender, e);
BuildMRUMenu();
extendedPanelPhones.CardInfoRemoved += (sender, e) => CardInfoRemoved?.Invoke(sender, e);
extendedPanelWeb.CardInfoRemoved += (sender, e) => CardInfoRemoved?.Invoke(sender, e);
BuildMRUMenu();
}
private void tbsOpen_Click(object sender, EventArgs e)
{
NewFileOpened?.Invoke(sender, new EventArg<string>(string.Empty));
OpenFile(sender, string.Empty);
}
private void OpenFile(object sender, string filename)
{
var evt = new EventArg<string>(filename);
NewFileOpened?.Invoke(sender, new EventArg<string>(filename));
if (!evt.CanCancel)
LastRowIndex = -1;
}
public void DisplayContacts(SortableBindingList<Contact> contacts)
{
bsContacts.DataSource = null;
if (contacts != null)
bsContacts.DataSource = contacts;
}
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.
Validate();
//Make sure to save changes for the current row.
dgContacts_RowLeave(null, null);
SaveContactsSelected(sender, e);
}
}
private void tbsNew_Click(object sender, EventArgs e)
@@ -96,13 +122,23 @@ namespace vCardEditor.View
private void dgContacts_SelectionChanged(object sender, EventArgs e)
{
if (ChangeContactsSelected != null && dgContacts.CurrentCell != null)
if (dgContacts.CurrentCell == null)
return;
//Weired, the selection is fired multiple times...
int RowIndex = dgContacts.CurrentCell.RowIndex;
if (LastRowIndex != RowIndex)
{
vCard data = GetvCardFromWindow();
ChangeContactsSelected(sender, new EventArg<vCard>(data));
if (ChangeContactsSelected != null && dgContacts.CurrentCell != null)
{
vCard data = GetvCardFromWindow();
ChangeContactsSelected(sender, new EventArg<vCard>(data));
}
else
ChangeContactsSelected(sender, new EventArg<vCard>(null));
LastRowIndex = RowIndex;
}
else
ChangeContactsSelected(sender, new EventArg<vCard>(null));
}
private void Value_TextChanged(object sender, EventArgs e)
@@ -112,14 +148,13 @@ namespace vCardEditor.View
public void DisplayContactDetail(vCard card, string FileName)
{
if (card == null)
throw new ArgumentException("vCard must be valid!");
ClearContactDetail();
Text = string.Format("{0} - vCard Editor", FileName);
//gbContactDetail.Enabled = true;
Text = string.Format("{0} - vCard Editor", FileName ?? "New file");
tcMainTab.Enabled = true;
gbNameList.Enabled = true;
@@ -128,71 +163,58 @@ namespace vCardEditor.View
SetSummaryValue(lastNameValue, card.FamilyName);
SetSummaryValue(middleNameValue, card.AdditionalNames);
SetSummaryValue(FormattedNameValue, card.FormattedName);
SetAddressesValues(card);
SetPhotoValue(card.Photos);
SetExtraInfos(card);
SetExtraTabFields(card);
}
private void SetExtraInfos(vCard card)
{
foreach (var item in card.EmailAddresses)
{
extendedPanelWeb.AddControl(item);
}
foreach (var item in card.Websites)
{
extendedPanelWeb.AddControl(item);
}
foreach (var item in card.Phones)
{
foreach (vCardPhone item in card.Phones)
extendedPanelPhones.AddControl(item);
}
}
foreach (vCardEmailAddress item in card.EmailAddresses)
extendedPanelWeb.AddControl(item);
foreach (vCardWebsite item in card.Websites)
extendedPanelWeb.AddControl(item);
}
private void SetExtraTabFields(vCard card)
{
if (card.Notes.Count > 0)
{
foreach (var note in card.Notes)
AddExtraTextGroup(vCardPropeties.NOTE, note.Text);
}
foreach (vCardNote note in card.Notes)
AddExtraTextGroup(vCardPropeties.NOTE, note.Text);
if (!string.IsNullOrEmpty(card.Organization))
{
AddExtraTextGroup(vCardPropeties.ORG, card.Organization);
}
}
public void AddExtraTextGroup(vCardPropeties type, string content)
{
ExtraTextGroup etg = new ExtraTextGroup();
etg.Content = content;
etg.Caption = type.ToString() + " :";
etg.CardProp = type;
ExtraTextGroup etg = new ExtraTextGroup
{
Content = content,
Caption = type.ToString() + ":",
CardProp = type,
Dock = DockStyle.Top
};
etg.TextChangedEvent += (sender, e) => TextBoxValueChanged?.Invoke(sender, e);
etg.ControlDeleted += (sender, e) =>
{
var send = sender as Control;
flowLayoutPanel1.Controls.Remove(send.Parent);
if (AskMessage("Are you sure?", "Question"))
panelTabExtra.Controls.Remove((sender as Control).Parent);
};
flowLayoutPanel1.Controls.Add(etg);
panelTabExtra.Controls.Add(etg);
}
public void ClearContactDetail()
{
//gbContactDetail.Enabled = false;
tcMainTab.Enabled = false;
gbNameList.Enabled = false;
@@ -202,11 +224,8 @@ namespace vCardEditor.View
SetSummaryValue(FormattedTitleValue, string.Empty);
SetSummaryValue(FormattedNameValue, string.Empty);
//SetAddressesValues(new vCard());
SetPhotoValue(new vCardPhotoCollection());
flowLayoutPanel1.Controls.Clear();
panelTabExtra.Controls.Clear();
extendedPanelPhones.ClearFields();
extendedPanelWeb.ClearFields();
}
@@ -225,7 +244,7 @@ namespace vCardEditor.View
{
if (photos.Any())
{
var photo = photos[0];
vCardPhoto photo = photos[0];
try
{
// Get the bytes of the photo if it has not already been loaded.
@@ -242,8 +261,8 @@ namespace vCardEditor.View
}
else
PhotoBox.Image = (Image)resources.GetObject("PhotoBox.Image");
}
private void SetAddressesValues(vCard card)
{
tbcAddress.SetAddresses(card);
@@ -269,77 +288,71 @@ namespace vCardEditor.View
{
//Save before leaving contact.
BeforeLeavingContact?.Invoke(sender, new EventArg<vCard>(GetvCardFromWindow()));
FilterTextChanged?.Invoke(sender, new EventArg<string>(textBoxFilter.Text));
LastRowIndex = -1;
dgContacts.ClearSelection();
textBoxFilter.Focus();
}
private vCard GetvCardFromWindow()
{
vCard card = new vCard
{
Title = FormattedTitleValue.Text,
FormattedName = FormattedNameValue.Text,
GivenName = firstNameValue.Text,
AdditionalNames = middleNameValue.Text,
FamilyName = lastNameValue.Text,
};
tbcAddress.getDeliveryAddress(card);
getExtraPhones(card);
getExtraWeb(card);
getExtraData(card);
return card;
}
private void getExtraPhones(vCard card)
{
card.Phones.Clear();
foreach (var item in extendedPanelPhones.GetExtraFields())
foreach (vCardRoot item in extendedPanelPhones.GetExtraFields())
{
if (item is vCardPhone)
if (item is vCardPhone)
{
vCardPhone phone = item as vCardPhone;
card.Phones.Add(phone);
}
}
}
private void getExtraWeb(vCard card)
{
card.Websites.Clear();
card.EmailAddresses.Clear();
foreach (var item in extendedPanelWeb.GetExtraFields())
foreach (vCardRoot item in extendedPanelWeb.GetExtraFields())
{
switch (item)
{
case vCardEmailAddress email:
card.EmailAddresses.Add(email);
break;
case vCardWebsite website:
card.Websites.Add(website);
break;
default:
break;
}
}
}
private void getExtraData(vCard card)
{
foreach (var item in flowLayoutPanel1.Controls)
foreach (object item in panelTabExtra.Controls)
{
var tbc = item as ExtraTextGroup;
ExtraTextGroup tbc = item as ExtraTextGroup;
switch (tbc.CardProp)
{
case vCardPropeties.NOTE:
@@ -365,12 +378,12 @@ namespace vCardEditor.View
Close();
}
private void MainForm_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
}
private void MainForm_DragDrop(object sender, DragEventArgs e)
{
string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
@@ -380,20 +393,14 @@ namespace vCardEditor.View
return;
}
NewFileOpened(sender, new EventArg<string>(FileList[0]));
OpenFile(sender, FileList[0]);
}
private void BuildMRUMenu()
{
recentFilesMenuItem.DropDownItemClicked += (s, e) =>
{
var evt = new EventArg<string>(e.ClickedItem.Text);
NewFileOpened(s, evt);
};
//TODO: Open File or Folder.
recentFilesMenuItem.DropDownItemClicked += (s, e) => OpenFile(s, e.ClickedItem.Text);
UpdateMRUMenu(ConfigRepository.Instance.Paths);
}
public void UpdateMRUMenu(FixedList MostRecentFilesList)
@@ -404,7 +411,6 @@ namespace vCardEditor.View
recentFilesMenuItem.DropDownItems.Clear();
for (int i = 0; i < MostRecentFilesList._innerList.Count; i++)
recentFilesMenuItem.DropDownItems.Add(MostRecentFilesList[i]);
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
@@ -413,19 +419,12 @@ namespace vCardEditor.View
CloseForm?.Invoke(sender, evt);
e.Cancel = evt.Data;
}
public bool AskMessage(string msg, string caption)
{
bool result = true; // true == yes
DialogResult window = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo);
if (window != DialogResult.No)
result = false;
return result;
return window == DialogResult.Yes;
}
private void miConfig_Click(object sender, EventArgs e)
@@ -437,7 +436,8 @@ namespace vCardEditor.View
{
MessageBox.Show(msg, caption);
}
public string DisplayOpenDialog(string filter = "")
public string DisplayOpenFileDialog(string filter = "")
{
string filename = string.Empty;
openFileDialog.Filter = filter;
@@ -449,25 +449,29 @@ namespace vCardEditor.View
return filename;
}
public string DisplaySaveDialog(string filename)
public string DisplaySaveDialog()
{
var saveFileDialog = new SaveFileDialog
SaveFileDialog saveFileDialog = new SaveFileDialog
{
FileName = filename
Title = "Save vCard file",
Filter = "Virtual Contact File|*.vcf"
};
string filename = null;
DialogResult result = saveFileDialog.ShowDialog();
if (result == DialogResult.OK)
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
filename = saveFileDialog.FileName;
Text = string.Format("{0} - vCard Editor", filename);
}
return filename;
}
private void PhotoBox_Click(object sender, EventArgs e)
{
if (ModifyImage != null)
{
var fileName = DisplayOpenDialog();
string fileName = DisplayOpenFileDialog();
if (!string.IsNullOrEmpty(fileName))
{
try
@@ -480,11 +484,13 @@ namespace vCardEditor.View
{
MessageBox.Show($"Invalid file! : {fileName}");
}
}
}
}
public void ClearImageFromForm()
{
PhotoBox.Image = (Image)resources.GetObject("PhotoBox.Image");
}
private void btnRemoveImage_Click(object sender, EventArgs e)
@@ -515,19 +521,17 @@ namespace vCardEditor.View
{
e.ContextMenuStrip = contextMenuStrip1;
}
}
private void modifiyColumnsToolStripMenuItem_Click(object sender, EventArgs e)
{
List<Column> Columns = GetListColumnsForDataGrid();
var dialog = new ColumnsDialog(Columns);
ColumnsDialog dialog = new ColumnsDialog(Columns);
if (dialog.ShowDialog() == DialogResult.OK)
{
ToggleAllColumnsToInvisible();
ToggleOnlySelected(dialog.Columns);
}
}
@@ -538,19 +542,17 @@ namespace vCardEditor.View
{
if (dgContacts.Columns[i].Visible)
{
var name = dgContacts.Columns[i].Name;
var enumType = (Column)Enum.Parse(typeof(Column), name, true);
string name = dgContacts.Columns[i].Name;
Column enumType = (Column)Enum.Parse(typeof(Column), name, true);
Columns.Add(enumType);
}
}
return Columns;
}
private void ToggleOnlySelected(List<Column> columns)
{
foreach (var item in columns)
foreach (Column item in columns)
{
switch (item)
{
@@ -574,7 +576,6 @@ namespace vCardEditor.View
public FormState GetFormState()
{
return new FormState
{
Columns = GetListColumnsForDataGrid(),
@@ -590,7 +591,6 @@ namespace vCardEditor.View
{
var evt = new EventArg<FormState>(new FormState());
LoadForm?.Invoke(sender, evt);
}
public void LoadIntialState(FormState state)
@@ -607,6 +607,17 @@ namespace vCardEditor.View
}
}
private void tbsQR_Click(object sender, EventArgs e)
{
ExportQR?.Invoke(sender, e);
}
public void DisplayQRCode(string content)
{
QRDialog qr = new QRDialog(content);
qr.ShowDialog();
}
private void addNotesToolStripMenuItem_Click(object sender, EventArgs e)
{
var evt = new EventArg<vCardPropeties>(vCardPropeties.NOTE);
@@ -619,15 +630,81 @@ namespace vCardEditor.View
AddExtraField?.Invoke(sender, evt);
}
private void tbsQR_Click(object sender, EventArgs e)
private void btnAddExtraText_Click(object sender, EventArgs e)
{
ExportQR?.Invoke(sender, e);
Button btnSender = (Button)sender;
Point ptLowerLeft = new Point(0, btnSender.Height);
ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
menuExtraField.Show(ptLowerLeft);
}
public void DisplayQRCode(string content)
private void miNote_Click(object sender, EventArgs e)
{
QRDialog qr = new QRDialog(content);
qr.ShowDialog();
var evt = new EventArg<vCardPropeties>(vCardPropeties.NOTE);
AddExtraField?.Invoke(sender, evt);
}
private void miOrg_Click(object sender, EventArgs e)
{
var evt = new EventArg<vCardPropeties>(vCardPropeties.ORG);
AddExtraField?.Invoke(sender, evt);
}
private void panelTabExtra_ControlAdded(object sender, ControlEventArgs e)
{
TapPageExtra.Text = string.Format("Extra ({0})", panelTabExtra.Controls.Count);
}
private void panelTabExtra_ControlRemoved(object sender, ControlEventArgs e)
{
TapPageExtra.Text = string.Format("Extra ({0})", panelTabExtra.Controls.Count);
}
private void countToolStripMenuItem_Click(object sender, EventArgs e)
{
CountImagesEvent?.Invoke(sender, e);
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
ClearImagesEvent?.Invoke(sender, e);
}
private void exportToolStripMenuItem_Click(object sender, EventArgs e)
{
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()
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
return dialog.SelectedPath;
return string.Empty;
}
public void LoadLocalizedUI(IReadOnlyDictionary<string, string> currentMessages)
{
//this.fileToolStripMenuItem.Text = currentMessages["MSG_002"];
}
public void LoadAvailablesLangs(IEnumerable<string> availableLanguages)
{
foreach (string lang in availableLanguages)
{
}
}
}
}

View File

@@ -336,6 +336,12 @@
XvxneHv7DU8zWBta5VGXAAAAAElFTkSuQmCC
</value>
</data>
<metadata name="menuExtraField.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>804, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAkAAAAAAAEAIAAHLwAAlgAAAICAAAABACAAKAgBAJ0vAABgYAAAAQAgAKiUAADFNwEASEgAAAEA

View File

@@ -29,8 +29,6 @@ namespace vCardEditor.View
pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(20, Color.Black, Color.White, null, 1);
pictureBoxQRCode.Size = new Size(pictureBoxQRCode.Width, pictureBoxQRCode.Height);
pictureBoxQRCode.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
@@ -61,30 +59,27 @@ namespace vCardEditor.View
}
else
{
using (FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile())
using (FileStream fs = (FileStream)saveFileDialog1.OpenFile())
{
ImageFormat imageFormat = null;
switch (saveFileDialog1.FilterIndex)
{
case 1:
imageFormat = ImageFormat.Bmp;
break;
case 2:
imageFormat = ImageFormat.Png;
break;
case 3:
imageFormat = ImageFormat.Jpeg;
break;
case 4:
imageFormat = ImageFormat.Gif;
break;
default:
throw new NotSupportedException("File extension is not supported");
}
pictureBoxQRCode.BackgroundImage.Save(fs, imageFormat);
ImageFormat imageFormat = null;
switch (saveFileDialog1.FilterIndex)
{
case 1:
imageFormat = ImageFormat.Bmp;
break;
case 2:
imageFormat = ImageFormat.Png;
break;
case 3:
imageFormat = ImageFormat.Jpeg;
break;
case 4:
imageFormat = ImageFormat.Gif;
break;
default:
throw new NotSupportedException("File extension is not supported");
}
pictureBoxQRCode.BackgroundImage.Save(fs, imageFormat);
}
}
}

View File

@@ -95,5 +95,33 @@ 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!).
bool 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();
}
}
}
}

View File

@@ -0,0 +1,19 @@
{
"version": "1.0",
"languages": {
"en": {
"name": "English",
"messages": {
"MSG_001": "Save current file before?",
"MSG_002": "File"
}
},
"fr": {
"name": "Français",
"messages": {
"MSG_001": "Sauvegarder le fichier en cours",
"MSG_002": "Fichier"
}
}
}
}

View File

@@ -57,6 +57,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
@@ -66,6 +67,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ILocalizationProvider.cs" />
<Compile Include="JsonLocalizationProvider.cs" />
<Compile Include="Libs\QRCoder\AbstractQRCode.cs" />
<Compile Include="Libs\QRCoder\ArtQRCode.cs" />
<Compile Include="Libs\QRCoder\ASCIIQRCode.cs" />
@@ -83,6 +86,11 @@
<Compile Include="Libs\QRCoder\QRCodeData.cs" />
<Compile Include="Libs\QRCoder\QRCodeGenerator.cs" />
<Compile Include="Libs\QRCoder\SvgQRCode.cs" />
<Compile Include="Libs\TinyJson\IParser.cs" />
<Compile Include="Libs\TinyJson\JSONParser.cs" />
<Compile Include="Libs\TinyJson\LocalizationFile.cs" />
<Compile Include="Libs\TinyJson\LocalizationLoader.cs" />
<Compile Include="Libs\TinyJson\TinyJsonParser.cs" />
<Compile Include="Model\vCardPropeties.cs" />
<Compile Include="Model\Column.cs" />
<Compile Include="Model\FixedList.cs" />
@@ -99,51 +107,50 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repository\Interfaces\IFileHandler.cs" />
<Compile Include="Thought.vCards\vCard.cs" />
<Compile Include="Thought.vCards\vCardAccessClassification.cs" />
<Compile Include="Thought.vCards\vCardCertificate.cs" />
<Compile Include="Thought.vCards\vCardCertificateCollection.cs" />
<Compile Include="Thought.vCards\vCardCollection.cs" />
<Compile Include="Thought.vCards\vCardDeliveryAddress.cs" />
<Compile Include="Thought.vCards\vCardDeliveryAddressCollection.cs" />
<Compile Include="Thought.vCards\vCardDeliveryAddressTypes.cs" />
<Compile Include="Thought.vCards\vCardDeliveryLabel.cs" />
<Compile Include="Thought.vCards\vCardDeliveryLabelCollection.cs" />
<Compile Include="Thought.vCards\vCardEmailAddress.cs" />
<Compile Include="Thought.vCards\vCardEmailAddressCollection.cs" />
<Compile Include="Thought.vCards\vCardEmailAddressType.cs" />
<Compile Include="Thought.vCards\vCardEncoding.cs" />
<Compile Include="Thought.vCards\vCardException.cs" />
<Compile Include="Thought.vCards\vCardFormat.cs" />
<Compile Include="Thought.vCards\vCardGender.cs" />
<Compile Include="Thought.vCards\vCardIMPP.cs" />
<Compile Include="Thought.vCards\vCardIMPPCollection.cs" />
<Compile Include="Thought.vCards\vCardNote.cs" />
<Compile Include="Thought.vCards\vCardNoteCollection.cs" />
<Compile Include="Thought.vCards\vCardPhone.cs" />
<Compile Include="Thought.vCards\vCardPhoneCollection.cs" />
<Compile Include="Thought.vCards\vCardPhoneTypes.cs" />
<Compile Include="Thought.vCards\vCardPhoto.cs" />
<Compile Include="Thought.vCards\vCardPhotoCollection.cs" />
<Compile Include="Thought.vCards\vCardProperty.cs" />
<Compile Include="Thought.vCards\vCardPropertyCollection.cs" />
<Compile Include="Thought.vCards\vCardReader.cs" />
<Compile Include="Thought.vCards\vCardRoot.cs" />
<Compile Include="Thought.vCards\vCardSocialProfile.cs" />
<Compile Include="Thought.vCards\vCardSocialProfileCollection.cs" />
<Compile Include="Thought.vCards\vCardSource.cs" />
<Compile Include="Thought.vCards\vCardSourceCollection.cs" />
<Compile Include="Thought.vCards\vCardStandardReader.cs" />
<Compile Include="Thought.vCards\vCardStandardWriter.cs" />
<Compile Include="Thought.vCards\vCardStandardWriterOptions.cs" />
<Compile Include="Thought.vCards\vCardSubproperty.cs" />
<Compile Include="Thought.vCards\vCardSubpropertyCollection.cs" />
<Compile Include="Thought.vCards\vCardValueCollection.cs" />
<Compile Include="Thought.vCards\vCardWebsite.cs" />
<Compile Include="Thought.vCards\vCardWebsiteCollection.cs" />
<Compile Include="Thought.vCards\vCardWebsiteTypes.cs" />
<Compile Include="Thought.vCards\vCardWriter.cs" />
<Compile Include="Thought.vCards\WarningMessages.Designer.cs" />
<Compile Include="Libs\Thought.vCards\vCard.cs" />
<Compile Include="Libs\Thought.vCards\vCardAccessClassification.cs" />
<Compile Include="Libs\Thought.vCards\vCardCertificate.cs" />
<Compile Include="Libs\Thought.vCards\vCardCertificateCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardDeliveryAddress.cs" />
<Compile Include="Libs\Thought.vCards\vCardDeliveryAddressCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardDeliveryAddressTypes.cs" />
<Compile Include="Libs\Thought.vCards\vCardDeliveryLabel.cs" />
<Compile Include="Libs\Thought.vCards\vCardDeliveryLabelCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardEmailAddress.cs" />
<Compile Include="Libs\Thought.vCards\vCardEmailAddressCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardEmailAddressType.cs" />
<Compile Include="Libs\Thought.vCards\vCardEncoding.cs" />
<Compile Include="Libs\Thought.vCards\vCardException.cs" />
<Compile Include="Libs\Thought.vCards\vCardFormat.cs" />
<Compile Include="Libs\Thought.vCards\vCardGender.cs" />
<Compile Include="Libs\Thought.vCards\vCardIMPP.cs" />
<Compile Include="Libs\Thought.vCards\vCardIMPPCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardNote.cs" />
<Compile Include="Libs\Thought.vCards\vCardNoteCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardPhone.cs" />
<Compile Include="Libs\Thought.vCards\vCardPhoneCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardPhoneTypes.cs" />
<Compile Include="Libs\Thought.vCards\vCardPhoto.cs" />
<Compile Include="Libs\Thought.vCards\vCardPhotoCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardProperty.cs" />
<Compile Include="Libs\Thought.vCards\vCardPropertyCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardReader.cs" />
<Compile Include="Libs\Thought.vCards\vCardRoot.cs" />
<Compile Include="Libs\Thought.vCards\vCardSocialProfile.cs" />
<Compile Include="Libs\Thought.vCards\vCardSocialProfileCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardSource.cs" />
<Compile Include="Libs\Thought.vCards\vCardSourceCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardStandardReader.cs" />
<Compile Include="Libs\Thought.vCards\vCardStandardWriter.cs" />
<Compile Include="Libs\Thought.vCards\vCardStandardWriterOptions.cs" />
<Compile Include="Libs\Thought.vCards\vCardSubproperty.cs" />
<Compile Include="Libs\Thought.vCards\vCardSubpropertyCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardValueCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardWebsite.cs" />
<Compile Include="Libs\Thought.vCards\vCardWebsiteCollection.cs" />
<Compile Include="Libs\Thought.vCards\vCardWebsiteTypes.cs" />
<Compile Include="Libs\Thought.vCards\vCardWriter.cs" />
<Compile Include="View\AboutDialog.cs">
<SubType>Form</SubType>
</Compile>
@@ -177,11 +184,11 @@
<Compile Include="View\Customs\ColumnsDialog.Designer.cs">
<DependentUpon>ColumnsDialog.cs</DependentUpon>
</Compile>
<Compile Include="View\Customs\CustumInputDialog.cs">
<Compile Include="View\Customs\CustomInputDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="View\Customs\CustumInputDialog.Designer.cs">
<DependentUpon>CustumInputDialog.cs</DependentUpon>
<Compile Include="View\Customs\CustomInputDialog.Designer.cs">
<DependentUpon>CustomInputDialog.cs</DependentUpon>
</Compile>
<Compile Include="View\Customs\ExtendedPanel.cs">
<SubType>UserControl</SubType>
@@ -211,7 +218,7 @@
<DependentUpon>QRDialog.cs</DependentUpon>
</Compile>
<Compile Include="View\SortableBindingList.cs" />
<Compile Include="View\StateTextBox.cs">
<Compile Include="View\Customs\StateTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="View\Customs\ExtraTextGroup.cs">
@@ -230,7 +237,6 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Thought.vCards\WarningMessages.resx" />
<EmbeddedResource Include="View\AboutDialog.resx">
<DependentUpon>AboutDialog.cs</DependentUpon>
</EmbeddedResource>
@@ -246,8 +252,8 @@
<EmbeddedResource Include="View\Customs\ColumnsDialog.resx">
<DependentUpon>ColumnsDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="View\Customs\CustumInputDialog.resx">
<DependentUpon>CustumInputDialog.cs</DependentUpon>
<EmbeddedResource Include="View\Customs\CustomInputDialog.resx">
<DependentUpon>CustomInputDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="View\Customs\ExtendedPanel.resx">
<DependentUpon>ExtendedPanel.cs</DependentUpon>
@@ -265,6 +271,7 @@
<DependentUpon>QRDialog.cs</DependentUpon>
</EmbeddedResource>
<None Include="app.config" />
<EmbeddedResource Include="i18n\lang.json" />
<None Include="Libs\QRCoder\Assets\nuget-readme.md" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>

View File

@@ -178,8 +178,7 @@ namespace vCardEditor_Test
repo.AddEmptyContact();
Assert.IsTrue(repo.Contacts.Count == 0);
Assert.IsTrue(repo.Contacts.Count == 1);
}
}
}

View File

@@ -0,0 +1,69 @@
namespace vCardEditor_Test
{
public class JsonEntries
{
public static string[] JsonEmtpy
{
get
{
return "".Split('\n');
}
}
public static string[] JsonIncorrect
{
get
{
return "abcdef".Split('\n');
}
}
public static string JsonValid
{
get
{
return @"{
""version"": ""1.0"",
""languages"": {
""en"": {
""name"": ""English"",
""messages"": {
""MSG_001"": ""Save current file before?"",
""MSG_002"": ""File""
}
},
""fr"": {
""name"": ""Français"",
""messages"": {
""MSG_001"": ""Sauvegarder le fichier en cours"",
""MSG_002"": ""Fichier""
}
}
}
}";
}
}
public static string InvalidJsonValid
{
get
{
return @"{
""version"": ""1.0"",
""languages"": {
""en"": {
""name"": ""English"",
""messages"": {
""MSG_001"": ""Save current file before?"",
""MSG_002"": ""File""
_002"": ""Fichier""
}
}
}
}";
}
}
}
}

View File

@@ -0,0 +1,26 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using System;
using vCardEditor.Libs.TinyJson;
using vCardEditor.Repository;
namespace vCardEditor_Test
{
[TestClass]
public class JsonLocalizationProviderTest
{
[TestMethod]
public void CorrectJsonLoaded_Test()
{
var fileHandler = Substitute.For<IFileHandler>();
fileHandler.LoadJsonFromAssembly(Arg.Any<string>()).Returns(JsonEntries.JsonValid);
var JsonParser = new TinyJsonParser();
var embeddedlang = new LocalizationLoader(JsonParser, fileHandler).LoadEmbedded();
Assert.IsTrue(embeddedlang.version == "1.0", "Json version incorrect");
Assert.IsTrue(embeddedlang.languages.Count == 2, "Number of json entries invalid");
}
}
}

View File

@@ -0,0 +1,38 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using vCardEditor.Libs.TinyJson;
using vCardEditor.Repository;
namespace vCardEditor_Test
{
[TestClass]
public class LocalizationLoaderTest
{
[TestMethod]
public void CorrectJsonLoaded_Test()
{
var fileHandler = Substitute.For<IFileHandler>();
fileHandler.LoadJsonFromAssembly(Arg.Any<string>()).Returns(JsonEntries.JsonValid);
var JsonParser = new TinyJsonParser();
var embeddedlang = new LocalizationLoader(JsonParser, fileHandler).LoadEmbedded();
Assert.IsTrue(embeddedlang.version == "1.0", "Json version incorrect");
Assert.IsTrue(embeddedlang.languages.Count == 2, "Number of json entries invalid");
}
[TestMethod]
public void IncorrectJsonLoaded_Test()
{
var fileHandler = Substitute.For<IFileHandler>();
fileHandler.LoadJsonFromAssembly(Arg.Any<string>()).Returns(JsonEntries.InvalidJsonValid);
var JsonParser = new TinyJsonParser();
var embeddedlang = new LocalizationLoader(JsonParser, fileHandler).LoadEmbedded();
Assert.IsTrue(embeddedlang.version == "1.0", "Json version incorrect");
}
}
}

Some files were not shown because too many files have changed in this diff Show More