Skip to content

Commit dde1ab5

Browse files
fix: default extension in direct editing
Signed-off-by: Luka Trovic <[email protected]>
1 parent c527cb0 commit dde1ab5

5 files changed

Lines changed: 88 additions & 9 deletions

File tree

l10n/ga.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ OC.L10N.register(
122122
"Save changes" : "Sabháil na hathruithe",
123123
"Cancel" : "Cealaigh",
124124
"URL" : "URL",
125-
"Attachments cannot be created or uploaded because this file is shared from another cloud." : "Ní féidir ceangaltáin a chruthú ná a uaslódáil mar go bhfuil an comhad seo roinnte ó scamall eile.",
126125
"Upload from computer" : "Íosluchtaigh ó ríomhaire",
127126
"Insert from Files" : "Ionsáigh ó Chomhaid",
128127
"Formatting help" : "Ionsáigh ó Chomhaid",
@@ -150,7 +149,6 @@ OC.L10N.register(
150149
"No command found" : "Níor aimsíodh aon ordú",
151150
"No user found" : "Níor aimsíodh aon úsáideoir",
152151
"No suggestion found" : "Níor aimsíodh aon mholadh",
153-
"Uploading attachments is disabled because the file is shared from another cloud." : "Tá uaslódáil ceangaltán díchumasaithe mar go bhfuil an comhad roinnte ó scamall eile.",
154152
"Upload" : "Uaslódáil",
155153
"Insert Table" : "Ionsáigh Tábla",
156154
"Smart Picker" : "Roghnóir Cliste",

l10n/ga.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"Save changes" : "Sabháil na hathruithe",
121121
"Cancel" : "Cealaigh",
122122
"URL" : "URL",
123-
"Attachments cannot be created or uploaded because this file is shared from another cloud." : "Ní féidir ceangaltáin a chruthú ná a uaslódáil mar go bhfuil an comhad seo roinnte ó scamall eile.",
124123
"Upload from computer" : "Íosluchtaigh ó ríomhaire",
125124
"Insert from Files" : "Ionsáigh ó Chomhaid",
126125
"Formatting help" : "Ionsáigh ó Chomhaid",
@@ -148,7 +147,6 @@
148147
"No command found" : "Níor aimsíodh aon ordú",
149148
"No user found" : "Níor aimsíodh aon úsáideoir",
150149
"No suggestion found" : "Níor aimsíodh aon mholadh",
151-
"Uploading attachments is disabled because the file is shared from another cloud." : "Tá uaslódáil ceangaltán díchumasaithe mar go bhfuil an comhad roinnte ó scamall eile.",
152150
"Upload" : "Uaslódáil",
153151
"Insert Table" : "Ionsáigh Tábla",
154152
"Smart Picker" : "Roghnóir Cliste",

lib/DirectEditing/TextDirectEditor.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCP\Files\InvalidPathException;
1818
use OCP\Files\NotFoundException;
1919
use OCP\Files\NotPermittedException;
20+
use OCP\IAppConfig;
2021
use OCP\IL10N;
2122
use OCP\Util;
2223

@@ -31,10 +32,16 @@ class TextDirectEditor implements IEditor {
3132
/** @var ApiService */
3233
private $apiService;
3334

34-
public function __construct(IL10N $l10n, InitialStateProvider $initialStateProvider, ApiService $apiService) {
35+
/**
36+
* @var IAppConfig
37+
*/
38+
private $appConfig;
39+
40+
public function __construct(IL10N $l10n, InitialStateProvider $initialStateProvider, ApiService $apiService, IAppConfig $appConfig) {
3541
$this->l10n = $l10n;
3642
$this->initialStateProvider = $initialStateProvider;
3743
$this->apiService = $apiService;
44+
$this->appConfig = $appConfig;
3845
}
3946

4047
/**
@@ -109,7 +116,7 @@ public function getMimetypesOptional(): array {
109116
*/
110117
public function getCreators(): array {
111118
return [
112-
new TextDocumentCreator($this->l10n),
119+
new TextDocumentCreator($this->l10n, $this->appConfig),
113120
];
114121
}
115122

lib/DirectEditing/TextDocumentCreator.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace OCA\Text\DirectEditing;
88

99
use OCP\DirectEditing\ACreateEmpty;
10+
use OCP\IAppConfig;
1011
use OCP\IL10N;
1112

1213
class TextDocumentCreator extends ACreateEmpty {
@@ -17,8 +18,14 @@ class TextDocumentCreator extends ACreateEmpty {
1718
*/
1819
private $l10n;
1920

20-
public function __construct(IL10N $l10n) {
21+
/**
22+
* @var IAppConfig
23+
*/
24+
private $appConfig;
25+
26+
public function __construct(IL10N $l10n, IAppConfig $appConfig) {
2127
$this->l10n = $l10n;
28+
$this->appConfig = $appConfig;
2229
}
2330

2431
public function getId(): string {
@@ -30,10 +37,16 @@ public function getName(): string {
3037
}
3138

3239
public function getExtension(): string {
33-
return 'md';
40+
return $this->appConfig->getValueString('text', 'default_file_extension', 'md');
3441
}
3542

3643
public function getMimetype(): string {
37-
return 'text/markdown';
44+
switch ($this->getExtension()) {
45+
case 'txt':
46+
return 'text/plain';
47+
case 'md':
48+
default:
49+
return 'text/markdown';
50+
}
3851
}
3952
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace OCA\Text\Tests;
4+
5+
use OCA\Text\DirectEditing\TextDocumentCreator;
6+
use OCP\IAppConfig;
7+
use OCP\IL10N;
8+
9+
class TextDocumentCreatorTest extends \PHPUnit\Framework\TestCase {
10+
private TextDocumentCreator $textDocumentCreator;
11+
12+
private IL10N $l10n;
13+
14+
private IAppConfig $appConfig;
15+
16+
protected function setUp(): void {
17+
$this->l10n = $this->createMock(IL10N::class);
18+
$this->appConfig = $this->createMock(IAppConfig::class);
19+
$this->textDocumentCreator = new TextDocumentCreator($this->l10n, $this->appConfig);
20+
}
21+
22+
public function testGetId(): void {
23+
$this->assertEquals('textdocument', $this->textDocumentCreator->getId());
24+
}
25+
26+
public function testGetName(): void {
27+
$this->l10n->expects($this->once())
28+
->method('t')
29+
->with('text document')
30+
->willReturn('text document');
31+
$this->assertEquals('text document', $this->textDocumentCreator->getName());
32+
}
33+
34+
public function testGetDefaultExtension(): void {
35+
$this->appConfig->expects($this->once())
36+
->method('getValueString')
37+
->with('text', 'default_file_extension', 'md')
38+
->willReturn('md');
39+
$this->assertEquals('md', $this->textDocumentCreator->getExtension());
40+
}
41+
42+
public function testGetExtensionFromConfig(): void {
43+
$this->appConfig->expects($this->once())
44+
->method('getValueString')
45+
->with('text', 'default_file_extension', 'md')
46+
->willReturn('txt');
47+
48+
$this->assertEquals('txt', $this->textDocumentCreator->getExtension());
49+
}
50+
51+
public function testGetDefaultMimetype(): void {
52+
$this->assertEquals('text/markdown', $this->textDocumentCreator->getMimetype());
53+
}
54+
55+
public function testGetMimetypeFromConfig(): void {
56+
$this->appConfig->expects($this->once())
57+
->method('getValueString')
58+
->with('text', 'default_file_extension', 'md')
59+
->willReturn('txt');
60+
61+
$this->assertEquals('text/plain', $this->textDocumentCreator->getMimetype());
62+
}
63+
}

0 commit comments

Comments
 (0)