Skip to content

Commit

Permalink
Added mousemap
Browse files Browse the repository at this point in the history
  • Loading branch information
dennykorsukewitz committed Jan 3, 2024
1 parent 723c690 commit d1ef9ff
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 2 deletions.
54 changes: 54 additions & 0 deletions __tests__/generators/mousemap.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const path = require('path');
const helpers = require('yeoman-test');

describe('generators:mousemap', () => {
describe('creates files', () => {
let runResult;

const config = {
// generator_data
mousemap_os: ['Default (Windows)', 'Default (OSX)', 'Default (Linux)'],

// package_data
sublime_version: '4.0.x',
package_name: 'Sublime-Package',
package_description: 'My description.',
github_username: 'dennykorsukewitz',
github_fullname: 'Denny Korsukéwitz',
};

const expectedFiles = [
'mousemaps/Default (Linux).sublime-mousemap',
'mousemaps/Default (OSX).sublime-mousemap',
'mousemaps/Default (Windows).sublime-mousemap',
];

const expectedContent = [
[ 'mousemaps/Default (Linux).sublime-mousemap', 'drag_select' ],
[ 'mousemaps/Default (OSX).sublime-mousemap', 'drag_select' ],
[ 'mousemaps/Default (Windows).sublime-mousemap', 'drag_select' ],
];

beforeEach(async () => {
runResult = await helpers
.run(path.join(process.env.INIT_CWD, '/generators/mousemap'))
.withPrompts(config)
.withLocalConfig(config);
});

afterEach(() => {
if (runResult) {
runResult.restore();
}
});

it('expected files', () => {
runResult.assertFile(expectedFiles);
});

it('expected content', () => {
runResult.assertFileContent(expectedContent);
});

});
});
13 changes: 13 additions & 0 deletions generators/mousemap/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Description:
Creates a Default.sublime-mousemap file.
The mousemap files (which have the extension .sublime-mousemap) control what commands are executed when a user performs an action with a mouse, e.g. clicking a mouse button, scrolling the scroll wheel, etc.

Example:
yo sublime-package:mousemap

This will create:
mousemaps/Default.sublime-mousemap: *.sublime-mousemap files contain a JSON array that contains JSON objects to specify the key bindings.

mousemaps/Default (Linux).sublime-mousemap
mousemaps/Default (OSX).sublime-mousemap
mousemaps/Default (Windows).sublime-mousemap
33 changes: 33 additions & 0 deletions generators/mousemap/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const config = {
name: 'Mousemap',
description: 'Creates a Default.sublime-mousemap file. Default.sublime-mousemap files contain the key bindings (shortcuts) for a command.',
priority: 70,
versions: {
'4.0.x': '',
},
prompts: [
{
name: 'mousemap_os',
message: 'For which operating system do you need a mousemap?',
type: 'checkbox',
choices: [
{
name: 'Windows',
value: 'Default (Windows)',
checked: true,
},
{
name: 'OSX',
value: 'Default (OSX)',
checked: true,
},
{
name: 'Linux',
value: 'Default (Linux)',
checked: true,
},
],
},
],
};
module.exports = config;
76 changes: 76 additions & 0 deletions generators/mousemap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';
/* eslint no-empty-function: ["error", { "allow": ["methods"] }] */

const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');
const path = require('path');
const helper = require('./../../src/helper.js');
const generator = path.basename(__dirname);
const generator_config = require('./config.js');

let config = {};
let answers = {};

module.exports = class extends Generator {
// initializing - Your initialization methods (checking current project state, getting configs, etc)
async initializing() {

// create or update config
await helper.InitConfig(this, generator_config);

// get current config
config = this.config.getAll();
config.generator_name = generator_config.name || generator;
config.generator_description = '\n' + generator_config.description || '';
}

// prompting - Where you prompt users for options (where you’d call this.prompt())
async prompting() {
this.log(
yosay(
`${chalk.green(config.generator_name)} ${config.generator_description}`,
),
);

generator_config.prompts = helper.InterpolatePrompts(this, config, generator_config.prompts);
answers = await this.prompt(generator_config.prompts);
}

// configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files)
configuring() {}

// default - If the method name doesn’t match a priority, it will be pushed to this group.
default() {}

// writing - Where you write the generator specific files (routes, controllers, etc)
writing() {

// merge data
const data = {
...config,
...answers,
};

answers.mousemap_os.forEach(os => {
this.renderTemplate(
this.templatePath('Default.sublime-mousemap'),
this.destinationPath(`mousemaps/${os}.sublime-mousemap`),
data,
);
});

}

// conflicts - Where conflicts are handled (used internally)
conflicts() { }

// install - Where installations are run (npm, bower)
install() {}

// end - Called last, cleanup, say good bye, etc
end() {
helper.End(this, config);
}
};

56 changes: 56 additions & 0 deletions generators/mousemap/templates/Default.sublime-mousemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[

// button: The name of the button.
// This defines the name of the button. There can be upto 16 buttons, button1 to button16 along with scroll_up & scroll_down for the scroll wheel.

// modifiers: A list of modifier keys.
// This defines a list of modifiers keys that have to be pressed simultaneously (along with the corresponding button click) for the command to be triggered, e.g. ["ctrl", "alt"]. A list of all the modifier keys can be found in the keybindings section on Modifiers.

// count: The count of the button press.
// This defines the number of times the button has to be pressed for the corresponding command to trigger. Defaults to 1.

// command: The command to execute.
// This defines the command to be executed when the corresponding button is released.

// args: The arguments for command.
// This is a mapping of arguments to be passed on to the command.

// press_command: The press_command to execute.
// This defines the command to be executed when the corresponding button is pressed.

// press_args: The arguments for press_command.
// This is a mapping of arguments to be passed on to the press_command.

// ---
// Examples:
// ---

// Basic drag select
{
"button": "button1", "count": 1,
"press_command": "drag_select"
},
{
"button": "button1", "count": 1, "modifiers": ["ctrl"],
"press_command": "drag_select",
"press_args": {"additive": true}
},
{
"button": "button1", "count": 1, "modifiers": ["alt"],
"press_command": "drag_select",
"press_args": {"subtractive": true}
},

// Save all with click on scroll wheel
{
"button": "button3", "count": 1,
"press_command": "save_all",
},

// Double left click on scroll wheel opens a new window
{
"button": "button3", "count": 2,
"press_command": "new_window",
},

]
2 changes: 1 addition & 1 deletion generators/project/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {
name: 'Project',
description: 'Creates a SublimePackage.sublime-project file to register a collection of files and folders, which are shown in Sidebar.',
priority: 70,
priority: 80,
versions: {
'4.0.x': '',
},
Expand Down
2 changes: 1 addition & 1 deletion generators/setting/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const config = {
name: 'Setting',
description: 'Creates a SublimePackage.sublime-settings file to stores configuration data.',
priority: 80,
priority: 90,
versions: {
'4.0.x': '',
},
Expand Down

0 comments on commit d1ef9ff

Please sign in to comment.