Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(developer): add user interface for kmc copy to TIKE #13076

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/windows/delphi/general/Upload_Settings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ interface
URLPath_KeymanDeveloper_KeymanForAndroidDownload = '/go/developer/'+SKeymanVersion+'/android-app';
URLPath_KeymanDeveloper_KeymanForIosDownload = '/go/developer/'+SKeymanVersion+'/ios-app';

URLPath_KeymanDeveloper_KeyboardSearchForCloneKeymanCloud = '/go/developer/'+SKeymanVersion+'/clone-keyboard';

URLPath_Support = '/go/'+SKeymanVersion+'/support';
URLPath_Privacy = '/go/'+SKeymanVersion+'/privacy';
URLPath_Privacy_Presentation = '/privacy';
Expand All @@ -71,6 +73,10 @@ interface
UrlPath_RegEx_MatchKeyboardsGo = '^http(?:s)?://keyman(?:-staging)?\.com(?:\.local)?/go/windows/[^/]+/download-keyboards';
// e.g. https://keyman-staging.com/go/windows/14.0/download-keyboards?version=14.0.146.0

// Cloning keyboards - Keyman Developer
URLSubPath_KeymanDeveloper_Clone_Keyboards = '/keyboards/';
URLSubPath_KeymanDeveloper_Clone_Keyboards_Custom = '/keyboards/h/';

function URLPath_PackageDownload(const PackageID, BCP47: string; IsUpdate: Boolean): string;

function API_Protocol: string; // = 'https';
Expand Down
24 changes: 16 additions & 8 deletions common/windows/delphi/general/utilfiletypes.pas
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
(*
Name: utilfiletypes
Copyright: Copyright (C) SIL International.
Documentation:
Description:
Documentation:
Description:
Create Date: 20 Jun 2006

Modified Date: 4 Dec 2006
Authors: mcdurdin
Related Files:
Dependencies:
Related Files:
Dependencies:

Bugs:
Todo:
Notes:
Bugs:
Todo:
Notes:
History: 20 Jun 2006 - mcdurdin - Initial version
01 Aug 2006 - mcdurdin - Refactor util functions into multiple units
04 Dec 2006 - mcdurdin - Add XML and HTML filetypes
Expand Down Expand Up @@ -100,7 +100,15 @@ TKeymanFileTypeInfo = class
end;

type
TKeymanProjectType = (kptUnknown, kptBasic, kptLDMLKeyboard, kptImportWindowsKeyboard, kptWordlistLexicalModel);
TKeymanProjectType = (
kptUnknown,
kptBasic,
kptLDMLKeyboard,
kptImportWindowsKeyboard,
kptWordlistLexicalModel,
kptCloneLocalProject,
kptCloneKeymanCloudProject,
kptCloneGitHubProject);

implementation

Expand Down
34 changes: 34 additions & 0 deletions developer/docs/help/context/clone-github-project-parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Clone GitHub Project Parameters Dialog
---

![Clone GitHub Project Parameters dialog](../images/ui/frmCloneGitHubProjectParameters.png)

Allows you to clone a project from a GitHub repository, giving the project a
new id, and organizing project files following the
[file layout](/developer/keyboards/) used in the
[Keyman keyboards repository](https://github.com/keymanapp/keyboards).

Keyboard and lexical model projects can be cloned.

Projects can also be cloned from the command line with [`kmc copy`](kmc).

### Parameters

GitHub URL:
: The full URL to a source project .kpj file to copy, on github.com.

Destination path
: Specifies the base path where the project folder will be created.
The project folder name will be the keyboard ID. If the folder
already exists, then you will be prompted before Keyman Developer
overwrites files inside it.

New project ID
: The base filename of the keyboard/model, project and package. This must
conform to the Keyman keyboard or lexical model identifier rules.

Relocate external files into new project folder
: When selected, if the project references files that are not inside the same
folder as the .kpj file, move these files into an `external` subfolder

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: Clone Keyman Cloud Project Parameters Dialog
---

![Clone Keyman Cloud Project Parameters dialog](../images/ui/frmCloneKeymanCloudProjectParameters.png)

Allows you to clone a project from Keyman Cloud, giving the project a
new id, and organizing project files following the
[file layout](/developer/keyboards/) used in the
[Keyman keyboards repository](https://github.com/keymanapp/keyboards).

Projects can also be cloned from the command line with [`kmc copy`](kmc).

Only keyboard projects can be cloned from Keyman Cloud at this time via this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the user tries to clone

  • a legacy keyboard where the source isn't available?
  • a multi-keyboard package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good questions. The legacy keyboard would generate an error in the kmc-copy log, so the user would get feedback that way. An open source multi-keyboard package should copy fine -- the .kpj and .kps would get the new id, but the keyboards within would retain their original names. Would be worth a test for each of these, and so I'll give that a go.

dialog. Lexical model projects can be cloned from Keyman Cloud via the command
line.

Search for a keyboard using the standard keyman.com keyboard search in the upper
pane. Once you select a keyboard, and fill in the New Project Details, the OK
button will be enabled to allow you to finish the cloning process.

### Parameters

Destination path
: Specifies the base path where the project folder will be created.
The project folder name will be the keyboard ID. If the folder
already exists, then you will be prompted before Keyman Developer
overwrites files inside it.

New project ID
: The base filename of the keyboard, project and package. This must
conform to the Keyman keyboard identifier rules.

Relocate external files into new project folder
: When selected, if the project references files that are not inside the same
folder as the .kpj file, move these files into an `external` subfolder

34 changes: 34 additions & 0 deletions developer/docs/help/context/clone-local-project-parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Clone Local Project Parameters Dialog
---

![Clone Local Project Parameters dialog](../images/ui/frmCloneLocalProjectParameters.png)

Allows you to clone a project from your local filesystem, giving the project a
new id, and organizing project files following the
[file layout](/developer/keyboards/) used in the
[Keyman keyboards repository](https://github.com/keymanapp/keyboards).

Keyboard and lexical model projects can be cloned.

Projects can also be cloned from the command line with [`kmc copy`](kmc).

### Parameters

Source project filename
: The full path of the source project .kpj file to copy.

Destination path
: Specifies the base path where the project folder will be created.
The project folder name will be the keyboard ID. If the folder
already exists, then you will be prompted before Keyman Developer
overwrites files inside it.

New project ID
: The base filename of the keyboard/model, project and package. This must
conform to the Keyman keyboard or lexical model identifier rules.

Relocate external files into new project folder
: When selected, if the project references files that are not inside the same
folder as the .kpj file, move these files into an `external` subfolder

26 changes: 25 additions & 1 deletion developer/docs/help/context/new-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,28 @@ Creates a keyboard project that matches the folder structure used in the Keyman

Creates a lexical model project that matches the folder structure used in the Keyman [lexical models repository](https://github.com/keymanapp/lexical-models) and includes all basic files needed for a lexical model project. Clicking OK will open the [New Lexical Model Project Parameters dialog](new-lm-project-parameters).

The **Basic** and **Import Windows Keyboard** modes can also be driven by command line with [KMConvert](kmconvert).
## Clone local project

Copies a Keyman keyboard or lexical model project on your local filesystem into
a new folder, giving the project and included files a new name. Clicking OK will
open the [Clone Local Project Parameters dialog](clone-local-project-parameters).

## Clone project from Keyman Cloud

Copies a Keyman keyboard or lexical model project from keyman.com into a new
folder, giving the project and included files a new name. Clicking OK will
open the [Clone Keyman Cloud Project Parameters dialog](clone-keyman-cloud-project-parameters).

## Clone project from GitHub

Copies a Keyman keyboard or lexical model project from a GitHub repository into
a new folder, giving the project and included files a new name. Clicking OK will
open the [Clone GitHub Project Parameters dialog](clone-github-project-parameters).

# Command line access

[`kmc generate`](kmc) can be used to generate new Keyman keyboards, LDML
keyboards, and Wordlist lexical models from the command line.

[KMConvert](kmconvert) can also be used to import Windows keyboards from the
command line.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified developer/docs/help/images/ui/frmNewProject.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ interface

type
TLexicalModelUtils = class
private
public
const SPackageNameDoesNotFollowLexicalModelConventions_Message: string =
'The package file %0:s does not follow the recommended model filename conventions. The name should be all lower case, '+
Expand All @@ -31,6 +30,8 @@ TLexicalModelUtils = class
class function CleanLexicalModelIDComponent(const Name: string): string; static;
class function IsCleanLexicalModelIDComponent(const Name: string): Boolean; static;

class function IsValidLexicalModelID(ID: string; EnforceCaseAndWhitespace: Boolean): Boolean; static;

class function ExtractFileExt(filename: string): string; static;
class function RemoveFileExt(filename: string): string; static;
class function ChangeFileExt(filename, ext: string): string; static;
Expand All @@ -51,11 +52,20 @@ implementation

// The model ID SHOULD adhere to this pattern (see also developer/src/kmc-model):
// author .bcp47 .uniq
MODEL_ID_PATTERN = '^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*$';
MODEL_ID_PATTERN_JS = '^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*\.model\.js$';
MODEL_ID_PATTERN_TS = '^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*\.model\.ts$';
MODEL_ID_PATTERN_PACKAGE = '^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*\.model\.(kps|kmp)$';
MODEL_ID_PATTERN_PROJECT = '^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_-]*\.[a-z_][a-z0-9_]*\.model\.kpj$';

class function TLexicalModelUtils.IsValidLexicalModelID(ID: string;
EnforceCaseAndWhitespace: Boolean): Boolean;
begin
if not EnforceCaseAndWhitespace then
ID := LowerCase(Trim(ID));
Result := TRegEx.IsMatch(ID, MODEL_ID_PATTERN);
end;

class function TLexicalModelUtils.DoesJSFilenameFollowLexicalModelConventions(
const Name: string): Boolean;
begin
Expand Down
Loading