Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 926ebbc

Browse files
committed
Working on spell check
1 parent 8c2329f commit 926ebbc

File tree

9 files changed

+368
-38
lines changed

9 files changed

+368
-38
lines changed

SubtitleEdit/UILogic/SpellCheck/SpellChecker.cs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using AppKit;
44
using Nikse.SubtitleEdit.Core;
55
using System.Linq;
6+
using System.Text;
7+
using Foundation;
68

79
namespace SpellCheck
810
{
@@ -17,12 +19,10 @@ public SpellChecker(string language)
1719
}
1820

1921
public bool Spell(string word)
20-
{
21-
// var x = new Foundation.NSOrthography(new Foundation.NSCoder());
22-
// nint wordCount;
23-
var result = _nativeSpellChecker.CheckSpelling(word, 0);
24-
// var results = _nativeSpellChecker.CheckString(word, new Foundation.NSRange(0, word.Length), new Foundation.NSTextCheckingTypes(), new Foundation.NSDictionary(), 0, out x, out wordCount);
25-
return result.Length == 0;
22+
{
23+
nint wordCount = 0;
24+
var res = _nativeSpellChecker.CheckSpelling(word, 0, "en",true, 0, out wordCount);
25+
return res.Location != 0;
2626
}
2727

2828
public List<string> Suggest(string word)
@@ -68,6 +68,32 @@ public string CurrentLanguage
6868
}
6969
}
7070

71+
72+
public const string WordSplitChars = " -.,?!:;\"“”()[]{}|<>/+\r\n¿¡…—–♪♫„“";
73+
74+
public static List<SpellCheckWord> Split(string s)
75+
{
76+
var list = new List<SpellCheckWord>();
77+
var sb = new StringBuilder();
78+
for (int i = 0; i < s.Length; i++)
79+
{
80+
if (SpellChecker.WordSplitChars.Contains(s[i]))
81+
{
82+
if (sb.Length > 0)
83+
list.Add(new SpellCheckWord { Text = sb.ToString(), Index = i - sb.Length });
84+
sb.Clear();
85+
}
86+
else
87+
{
88+
sb.Append(s[i]);
89+
}
90+
}
91+
if (sb.Length > 0)
92+
list.Add(new SpellCheckWord { Text = sb.ToString(), Index = s.Length - 1 - sb.Length });
93+
return list;
94+
}
95+
96+
7197
}
7298

7399
}

SubtitleEdit/Windows/Edit/SpellCheck.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Foundation;
44
using AppKit;
55
using Nikse.SubtitleEdit.Core;
6+
using System.Collections.Generic;
67

78
namespace Edit
89
{
@@ -30,7 +31,44 @@ public override void AwakeFromNib()
3031

3132
var l = Configuration.Settings.Language.SpellCheck;
3233
Title = l.Title;
34+
35+
(WindowController as SpellCheckController).InitializeSpellCheck();
36+
37+
_buttonAbort.Activated += (object sender, EventArgs e) =>
38+
{
39+
(WindowController as SpellCheckController).Abort();
40+
Close();
41+
};
42+
43+
_buttonSkipAll.Activated += (object sender, EventArgs e) =>
44+
{
45+
(WindowController as SpellCheckController).SkipAll();
46+
};
47+
48+
_buttonSkipOne.Activated += (object sender, EventArgs e) =>
49+
{
50+
(WindowController as SpellCheckController).SkipOne();
51+
_textWordNotFound.StringValue = string.Empty;
52+
};
53+
54+
55+
}
56+
57+
public void InitializeLanguages(List<string> list)
58+
{
59+
3360
}
3461

62+
public void ShowUnknownWord(SpellCheckWord currentSpellCheckWord, Paragraph currentParagraph)
63+
{
64+
_textWordNotFound.StringValue = currentSpellCheckWord.Text;
65+
}
66+
67+
public void ShowProgress(int currentParagraphIndex, Subtitle _subtitle)
68+
{
69+
_progressBar.MaxValue = _subtitle.Paragraphs.Count;
70+
_progressBar.DoubleValue = currentParagraphIndex;
71+
Title = Configuration.Settings.Language.SpellCheck.Title + " - " + (currentParagraphIndex + 1) + " / " + _subtitle.Paragraphs.Count;
72+
}
3573
}
3674
}

SubtitleEdit/Windows/Edit/SpellCheck.designer.cs

Lines changed: 96 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SubtitleEdit/Windows/Edit/SpellCheck.xib

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
33
<dependencies>
4+
<deployment identifier="macosx"/>
45
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
56
<capability name="box content view" minToolsVersion="7.0"/>
67
</dependencies>
78
<objects>
89
<customObject id="-2" userLabel="File's Owner" customClass="SpellCheckController">
910
<connections>
11+
<outlet property="_buttonAddToNamesList" destination="jpO-th-jbG" id="DzE-La-dFa"/>
12+
<outlet property="_buttonAddToUserDictionary" destination="0UH-tu-Gfd" id="I0q-qN-TYg"/>
13+
<outlet property="_buttonChange" destination="tuh-2M-xk3" id="URO-3C-JVB"/>
14+
<outlet property="_buttonChangeAll" destination="v83-AW-MRt" id="NvH-rb-stR"/>
15+
<outlet property="_buttonSkipAll" destination="gKC-4S-v11" id="ouV-FN-Ygo"/>
16+
<outlet property="_buttonSkipOne" destination="tYT-XV-uuX" id="Zx6-UT-pYo"/>
17+
<outlet property="_textWordNotFound" destination="OWS-S5-rnJ" id="fMk-qr-BtT"/>
1018
<outlet property="window" destination="2" id="6"/>
1119
</connections>
1220
</customObject>
1321
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
14-
<customObject id="-3" userLabel="Application"/>
22+
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
1523
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" animationBehavior="default" id="2" customClass="SpellCheck">
1624
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
1725
<rect key="contentRect" x="131" y="74" width="802" height="528"/>
@@ -79,7 +87,7 @@
7987
<button verticalHuggingPriority="750" id="gKC-4S-v11">
8088
<rect key="frame" x="177" y="89" width="163" height="32"/>
8189
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
82-
<buttonCell key="cell" type="push" title="Skil all" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ykN-9z-68e">
90+
<buttonCell key="cell" type="push" title="Skip all" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ykN-9z-68e">
8391
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
8492
<font key="font" metaFont="system"/>
8593
</buttonCell>
@@ -116,7 +124,7 @@
116124
</popUpButton>
117125
<button verticalHuggingPriority="750" id="YOp-4g-idH">
118126
<rect key="frame" x="698" y="13" width="90" height="32"/>
119-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
127+
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
120128
<buttonCell key="cell" type="push" title="Abort" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="8hh-xg-GAY">
121129
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
122130
<font key="font" metaFont="system"/>
@@ -131,8 +139,24 @@
131139
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
132140
</textFieldCell>
133141
</textField>
142+
<progressIndicator wantsLayer="YES" maxValue="100" style="bar" id="TKe-vR-bIk">
143+
<rect key="frame" x="22" y="19" width="648" height="20"/>
144+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
145+
</progressIndicator>
134146
</subviews>
135147
</view>
148+
<connections>
149+
<outlet property="_buttonAbort" destination="YOp-4g-idH" id="ULo-ZZ-z8f"/>
150+
<outlet property="_buttonAddToNames" destination="jpO-th-jbG" id="W7A-Cb-tR2"/>
151+
<outlet property="_buttonAddToUserDictionary" destination="0UH-tu-Gfd" id="0cW-My-aQQ"/>
152+
<outlet property="_buttonChange" destination="tuh-2M-xk3" id="CtI-6d-27u"/>
153+
<outlet property="_buttonChangeAll" destination="v83-AW-MRt" id="dIV-RH-Q6x"/>
154+
<outlet property="_buttonSkipAll" destination="gKC-4S-v11" id="SLa-Bf-BQc"/>
155+
<outlet property="_buttonSkipOne" destination="tYT-XV-uuX" id="m1h-oO-gP2"/>
156+
<outlet property="_popUpLanguages" destination="RhI-vO-aFT" id="T8D-75-Sxz"/>
157+
<outlet property="_progressBar" destination="TKe-vR-bIk" id="sI4-bA-Z5Y"/>
158+
<outlet property="_textWordNotFound" destination="OWS-S5-rnJ" id="2cW-7p-YGz"/>
159+
</connections>
136160
<point key="canvasLocation" x="706" y="513"/>
137161
</window>
138162
</objects>

0 commit comments

Comments
 (0)