Skip to content

Commit

Permalink
Merge pull request #18 from BalaDhruv/development
Browse files Browse the repository at this point in the history
Select Parent Set - Feature added
  • Loading branch information
BalaDhruv authored Jan 29, 2022
2 parents bb4ceec + fc0d41c commit 0928ca6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Refer the article to know about the extension.
4. Create Reducer
5. Create Middleware
6. Create Action
7. Add Variable to State
7. Select Parent Set (Select and Set Parent Set -> If you have moved your project extension will not remember parent set. you cen set parent set manually.)
8. Add Variable to State

## How to Use

Expand Down Expand Up @@ -50,6 +51,12 @@ Refer the article to know about the extension.
| Parent Set | Its a parent of all Set. Its configured by Us as a parent |
| Auto Import | When you create a set it will automatically imported to Parent Set |

## Command Palette

| Command | Description |
| :---------------- | :-------------------------------- |
| Select Parent Set | Select parent set from file tree. |

## Upcoming Features

1. Tree view of states - Explorer View
Expand Down
21 changes: 17 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "flutter-redux-gen",
"displayName": "Flutter Redux Gen (FRG)",
"description": "This is the VS Code Extension to generate Redux Code (State, Reducer, Middleware and Action).",
"version": "3.0.3",
"version": "3.0.5",
"publisher": "BalaDhruv",
"author": {
"name": "Balamurugan",
Expand Down Expand Up @@ -44,7 +44,8 @@
"onCommand:flutter-redux-gen.createMiddleware",
"onCommand:flutter-redux-gen.createAction",
"onCommand:flutter-redux-gen.createParentSet",
"onCommand:flutter-redux-gen.createVariableInState"
"onCommand:flutter-redux-gen.createVariableInState",
"onCommand:flutter-redux-gen.selectParentSet"
],
"main": "./out/extension.js",
"contributes": {
Expand Down Expand Up @@ -82,6 +83,11 @@
"command": "flutter-redux-gen.createVariableInState",
"title": "Add Variable to State",
"category": "Flutter Redux Gen"
},
{
"command": "flutter-redux-gen.selectParentSet",
"title": "Select Parent Set",
"category": "Flutter Redux Gen"
}
],
"menus": {
Expand Down Expand Up @@ -112,6 +118,9 @@
{
"command": "flutter-redux-gen.createVariableInState",
"when": "false"
},
{
"command": "flutter-redux-gen.selectParentSet"
}
],
"editor/context": [{
Expand All @@ -138,11 +147,15 @@
},
{
"command": "flutter-redux-gen.createMiddleware",
"group": "flg@4"
"group": "flg@5"
},
{
"command": "flutter-redux-gen.createAction",
"group": "flg@4"
"group": "flg@6"
},
{
"command": "flutter-redux-gen.selectParentSet",
"group": "flg@7"
}
]
}
Expand Down
36 changes: 30 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { CREATE_STATE_PLACE_HOLDER, NAME_ERROR_MESSAGE, CREATE_ACTION_PLACE_HOLDER, CREATE_MIDDLEWARE_PLACE_HOLDER, CREATE_REDUCER_PLACE_HOLDER, NAME_REG_EXP, DEFAULT_NAME, STATE_EXTENSION, REDUCER_EXTENSION, MIDDLEWARE_EXTENSION, ACTION_EXTENSION, ADD_VARIABLE_TO_STATE_PLACEHOLDER, VARIABLE_NAME_ERROR_MESSAGE, SELECT_PARENT_SET } from './resources/utils/constants';
import { CREATE_STATE_PLACE_HOLDER, NAME_ERROR_MESSAGE, CREATE_ACTION_PLACE_HOLDER, CREATE_MIDDLEWARE_PLACE_HOLDER, CREATE_REDUCER_PLACE_HOLDER, NAME_REG_EXP, DEFAULT_NAME, STATE_EXTENSION, REDUCER_EXTENSION, MIDDLEWARE_EXTENSION, ACTION_EXTENSION, ADD_VARIABLE_TO_STATE_PLACEHOLDER, VARIABLE_NAME_ERROR_MESSAGE, SELECT_PARENT_SET, NOT_FOUND_ANY_SET_FILE, NO_FOLDER_IN_WORKSPACE_FOUND, STATE_FILE_RELATIVE_PATTERN, CURRENT_PARENT, SUCCESFULLY_SET_PARENT } from './resources/utils/constants';
import { getStateGenCode, addVariableToState } from './resources/gen/state';
import { getFilePath } from './resources/utils/utils';
import { getReducerGenCode } from './resources/gen/reducer';
Expand Down Expand Up @@ -156,11 +156,6 @@ export function activate(context: vscode.ExtensionContext): void {

// Create Redux Set Command Registering
let createReduxSet = vscode.commands.registerCommand('flutter-redux-gen.createReduxSet', async (args) => {
if (!isParentSetExist(context)) {
// Checking to see if the project moved or opened if another vscode editor
// Try and find the parent Set
await checkAndSelectParentSetIfAlreadyExist(args, context);
}
let focusedFilePath = getFilePath(args.fsPath);
let nameField = vscode.window.createInputBox();
let nameFieldValidator = new RegExp(NAME_REG_EXP);
Expand Down Expand Up @@ -230,6 +225,35 @@ export function activate(context: vscode.ExtensionContext): void {
}
});

vscode.commands.registerCommand('flutter-redux-gen.selectParentSet', async (args) => {
const folders = vscode.workspace.workspaceFolders;
if (!folders) {
return vscode.window.showErrorMessage(NO_FOLDER_IN_WORKSPACE_FOUND);
}

const sets: vscode.Uri[] = [];
const fillSetsArray = folders.map(folder =>
vscode.workspace.findFiles(
new vscode.RelativePattern(folder, STATE_FILE_RELATIVE_PATTERN),
).then(files => sets.push(...files))
);

await Promise.all(fillSetsArray);

if (!sets.length) {
return vscode.window.showErrorMessage(NOT_FOUND_ANY_SET_FILE);
}

const parent = getParentName(context);
const placeHolder = parent ? CURRENT_PARENT.replace('<FILE>', parent) : '';

var set = await vscode.window.showQuickPick(sets.map(set => set.path), { title: SELECT_PARENT_SET, placeHolder });
if (set) {
saveParentSet(path.dirname(set), path.basename(set, STATE_EXTENSION), context);
vscode.window.showInformationMessage(SUCCESFULLY_SET_PARENT.replace('<FILE>', path.basename(set)));
}
});

context.subscriptions.push(createParentSet);

}
Expand Down
6 changes: 6 additions & 0 deletions src/resources/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ export const CREATE_ACTION_PLACE_HOLDER = 'Enter Action File Name';
export const SELECT_PARENT_SET = 'Select Parent Set';
export const NAME_ERROR_MESSAGE = 'Please use name without space. Consider using "_"';
export const VARIABLE_NAME_ERROR_MESSAGE = 'Please use name without space. Consider using camelCase';
export const NOT_FOUND_ANY_SET_FILE = `Not found any file with '${STATE_EXTENSION}' extension.`;
export const NO_FOLDER_IN_WORKSPACE_FOUND = 'There is no folder in workspace.';
export const CURRENT_PARENT = `Current parent is '<FILE>${STATE_EXTENSION}'`;
export const SUCCESFULLY_SET_PARENT = `Succesfully set '<FILE>' as parent.`;

export const NAME_REG_EXP = /[`0-9 ~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/;
export const STATE_FILE_RELATIVE_PATTERN = `**/*.state.dart`;
6 changes: 0 additions & 6 deletions src/resources/utils/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ async function _checkAndSelectParentSetIfAlreadyExist(args: any, context: vscode
saveParentSet(dir, path.basename(selectedSet, STATE_EXTENSION), context);
};

// function _getFlutterVersion(context: vscode.ExtensionContext) {
// console.log("INSIDE FLUTTER VERSION");
// console.log(context.logPath);
// console.log(context.workspaceState.get("PARENT_PATH"));
// }

export var createFile = _createFile;
export var createFolder = _createFolder;
export var isParentSetExist = _isParentSetExist;
Expand Down

0 comments on commit 0928ca6

Please sign in to comment.