Initial version of the Language editor (is standalone solution)

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1825 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-05-02 15:12:13 +00:00
parent 7c5169da69
commit fb9f45f3df
11 changed files with 525 additions and 0 deletions

View file

@ -0,0 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.2.0.8528-beta
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotLanguageEditor", "GreenshotLanguageEditor\GreenshotLanguageEditor.csproj", "{3938F7B8-BAA1-48A3-B910-5FA6A5AA2506}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3938F7B8-BAA1-48A3-B910-5FA6A5AA2506}.Debug|x86.Build.0 = Debug|x86
{3938F7B8-BAA1-48A3-B910-5FA6A5AA2506}.Debug|x86.ActiveCfg = Debug|x86
{3938F7B8-BAA1-48A3-B910-5FA6A5AA2506}.Release|x86.Build.0 = Release|x86
{3938F7B8-BAA1-48A3-B910-5FA6A5AA2506}.Release|x86.ActiveCfg = Release|x86
EndGlobalSection
EndGlobal

BIN
GreenshotLanguageEditor.suo Normal file

Binary file not shown.

View file

@ -0,0 +1,8 @@
<Application x:Class="GreenshotLanguageEditor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View file

@ -0,0 +1,15 @@
using System;
using System.Windows;
using System.Data;
using System.Xml;
using System.Configuration;
namespace GreenshotLanguageEditor
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

View file

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{3938F7B8-BAA1-48A3-B910-5FA6A5AA2506}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<RootNamespace>GreenshotLanguageEditor</RootNamespace>
<AssemblyName>GreenshotLanguageEditor</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Language.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\WPFAssemblyInfo.cs" />
<Compile Include="Window1.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>Window1.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Include="Window1.xaml" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

View file

@ -0,0 +1,80 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
namespace GreenshotLanguageEditor {
public class LanguageFile {
public string FilePath {
get;
set;
}
public string IETF {
get;
set;
}
public string Version {
get;
set;
}
public string Languagegroup {
get;
set;
}
public string Description {
get;
set;
}
}
/// <summary>
/// Description of Language.
/// </summary>
public static class GreenshotLanguage {
public static IEnumerable<LanguageFile> GetLanguageFiles(string languageFilePath, string languageFilePattern) {
var languageFiles = from languageFile in Directory.GetFiles(languageFilePath, languageFilePattern, SearchOption.AllDirectories).ToList<string>()
from language in XDocument.Load(languageFile).Descendants("language")
select new LanguageFile {
FilePath = languageFile,
Description = (string)language.Attribute("description"),
IETF = (string)language.Attribute("ietf"),
Version = (string)language.Attribute("version"),
Languagegroup = (string)language.Attribute("languagegroup")
};
foreach (LanguageFile languageFile in languageFiles) {
yield return languageFile;
}
}
public static IDictionary<string, string> ReadLanguageFile(LanguageFile languageFile) {
return (from resource in XDocument.Load(languageFile.FilePath).Descendants("resource")
where !string.IsNullOrEmpty(resource.Value)
select new {
Name = (string)resource.Attribute("name"),
Text = resource.Value.Trim()
}
).ToDictionary(item => item.Name, item => item.Text);
}
}
}

View file

@ -0,0 +1,31 @@
#region Using directives
using System;
using System.Reflection;
using System.Runtime.InteropServices;
#endregion
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("GreenshotLanguageEditor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GreenshotLanguageEditor")]
[assembly: AssemblyCopyright("Copyright 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

View file

@ -0,0 +1,27 @@
#region Using directives
using System.Resources;
using System.Windows;
#endregion
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View file

@ -0,0 +1,48 @@
<Window x:Class="GreenshotLanguageEditor.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Language editor" Height="400" Width="600">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" Grid.Column="0" Name="LanguageGrid" ItemsSource="{Binding View}" AutoGenerateColumns="False" IsReadOnly="False" IsSynchronizedWithCurrentItem="True">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Setters>
<Setter Property="Background" Value="{Binding Path=Background}"></Setter>
</Style.Setters>
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Key" Binding="{Binding Key}" Width="250"/>
<DataGridTextColumn Header="Language1" Binding="{Binding Entry1}" Width="*">
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="MaxHeight" Value="300"/>
<Setter Property="AcceptsReturn" Value="true" />
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Language2" Binding="{Binding Entry2}" Width="*">
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="TextBox">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="MaxHeight" Value="300"/>
<Setter Property="AcceptsReturn" Value="true" />
</Style>
</DataGridTextColumn.EditingElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Content="Save" Click="Button_Click"/>
<Button Content="Cancel" />
</StackPanel>
</Grid>
</Window>

View file

@ -0,0 +1,209 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.ComponentModel;
using System.Xml;
namespace GreenshotLanguageEditor {
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window {
public ICollectionView View {
get;
set;
}
public Window1() {
var dialog = new System.Windows.Forms.FolderBrowserDialog();
dialog.ShowNewFolderButton = false;
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
string languagePath;
if (result == System.Windows.Forms.DialogResult.OK) {
languagePath = dialog.SelectedPath;
} else {
this.Close();
return;
}
InitializeComponent();
View = CollectionViewSource.GetDefaultView(LoadResources(languagePath));
DataContext = this;
this.Activate();
}
private IList<LanguageEntry> LoadResources(string languagePath) {
IDictionary<string, LanguageEntry> languageResources = new SortedDictionary<string, LanguageEntry>();
foreach (LanguageFile languageFile in GreenshotLanguage.GetLanguageFiles(languagePath, "language*.xml")) {
if ("en-US".Equals(languageFile.IETF)) {
IDictionary<string, string> enResources = GreenshotLanguage.ReadLanguageFile(languageFile);
foreach(string key in enResources.Keys) {
LanguageEntry entry;
if (languageResources.ContainsKey(key)) {
entry = languageResources[key];
} else {
entry = new LanguageEntry();
entry.Key = key;
languageResources.Add(key, entry);
}
entry.Entry1 = enResources[key];
}
}
if ("de-DE".Equals(languageFile.IETF)) {
IDictionary<string, string> deResources = GreenshotLanguage.ReadLanguageFile(languageFile);
foreach(string key in deResources.Keys) {
LanguageEntry entry;
if (languageResources.ContainsKey(key)) {
entry = languageResources[key];
} else {
entry = new LanguageEntry();
entry.Key = key;
languageResources.Add(key, entry);
}
entry.Entry2 = deResources[key];
}
}
}
return new List<LanguageEntry>(languageResources.Values);
}
public void CreateXML(string savePath) {
ICollectionView view = (ICollectionView)LanguageGrid.ItemsSource;
IList<LanguageEntry> entries = (IList<LanguageEntry>)view.SourceCollection;
using (XmlTextWriter xmlWriter = new XmlTextWriter(savePath, Encoding.UTF8)) {
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.Indentation = 1;
xmlWriter.IndentChar = '\t';
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("language");
xmlWriter.WriteAttributeString("description", "testdescription");
xmlWriter.WriteAttributeString("ietf", "testietf");
xmlWriter.WriteAttributeString("version", "testversion");
xmlWriter.WriteAttributeString("languagegroup", "testlanguagegroup");
xmlWriter.WriteStartElement("resources");
foreach(LanguageEntry entry in entries) {
xmlWriter.WriteStartElement("resource");
xmlWriter.WriteAttributeString("name", entry.Key);
xmlWriter.WriteString(entry.Entry1);
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
}
}
private void Button_Click(object sender, RoutedEventArgs e) {
var dialog = new System.Windows.Forms.SaveFileDialog();
dialog.AutoUpgradeEnabled = true;
dialog.DefaultExt = ".xml";
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK) {
CreateXML(dialog.FileName);
} else {
this.Close();
return;
}
}
}
public class LanguageEntry : IEditableObject, INotifyPropertyChanged {
private string key;
private string entry1;
private string entry2;
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info) {
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public Brush Background {
get {
if (Entry1 == null) {
return Brushes.Red;
}
if (Entry2 == null) {
return Brushes.Red;
}
return Brushes.Green;
}
}
public string Key {
get {
return key;
}
set {
key = value;
NotifyPropertyChanged("Key");
}
}
public string Entry1 {
get {
return entry1;
}
set {
entry1 = value;
NotifyPropertyChanged("Entry1");
NotifyPropertyChanged("Background");
}
}
public string Entry2 {
get {
return entry2;
}
set {
entry2 = value;
NotifyPropertyChanged("Entry2");
NotifyPropertyChanged("Background");
}
}
public void BeginEdit() {
}
public void EndEdit() {
}
public void CancelEdit() {
}
}
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>