Skip to content

Commit

Permalink
Merge pull request #9 from thapp-com-br/update-wraps
Browse files Browse the repository at this point in the history
Update Wraps
  • Loading branch information
kauemurakami authored Sep 26, 2020
2 parents a3e3e91 + 4b5fc3e commit 5ce7090
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 209 deletions.
54 changes: 6 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ examples available in this repository:
### [Understand more about this structure and much more in our proposed pattern](https://kauemurakami.github.io/getx_pattern/)
## Example
[See complet exemple](https://github.com/kauemurakami/get_snippets_extension/tree/doc/examples)
[See complet exemple](https://github.com/kauemurakami/getx_snippets_extension/tree/master/examples)
not yet available
## Features
- [Classes](#classes)
Expand All @@ -75,11 +75,10 @@ not yet available
Here you will find snippets that will help you create widgets quickly and easily.
- [Widgets Component](#widgets-components)
Here you will find reusable widgets, made in a stateless widgets ready to be consumed by several widgets.
- ### Now you can use Wrap with our extension, this makes it easy when you need to change a complex widget tree without headaches, see the available Wrappers
- Wrap in GetX (alt + x)
- Wrap in Obx (alt + o)
- Wrap in GetBuilder (alt + g)
Using : Select your widget and click in lamp or use the shortcut.
## Wrap
![](examples/wraps.jpg)
## Classes
### getmain
Expand Down Expand Up @@ -333,47 +332,6 @@ getStorage
getStorageWrite
getStorageRead
## Releases Notes
### 3.1.0
WELCOME GETX 3.3 !!!
getx-snippets release 2.5
:octopus: New Features :octopus:
Wrap avaibles:
Wrap in GetX (alt + x)
Wrap in Obx (alt + o)
Wrap in GetBuilder (alt + g)
Using : Select your widget and click in lamp or use the shortcut.
New Snippets:
getPut
getFind
getLazyPut
getSnackbar
getDefaultDialog
getDialog
getBottomSheet
getonInit
getonClose
getToNamed
getOffNamed
getOffAllNamed
getTo
getOff
getOffAll
getStorage
getStorageWrite
getStorageRead
**Enjoy!**
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
Binary file added examples/wraps.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 19 additions & 70 deletions out/extension.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion out/extension.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "get-snippets",
"displayName": "GetX Snippets",
"description": "An extension to accelerate the process of developing applications with flutter, aimed at everyone using the Get package.",
"version": "3.1.3",
"version": "3.1.5",
"publisher": "get-snippets",
"engines": {
"vscode": "^1.2.0"
Expand Down Expand Up @@ -63,19 +63,19 @@
],
"keybindings": [
{
"command": "get.wrapInGetx",
"command": "get.removeKey",
"key": "alt+x",
"mac": "alt+x",
"when": "editorTextFocus"
},
{
"command": "get.wrapInGetBuilder",
"command": "get.removeKey",
"key": "alt+g",
"mac": "alt+g",
"when": "editorTextFocus"
},
{
"command": "get.wrapInObx",
"command": "get.removeKey",
"key": "alt+o",
"mac": "alt+o",
"when": "editorTextFocus"
Expand Down
117 changes: 31 additions & 86 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,10 @@

import * as vscode from "vscode";
import {SpaceX} from "./utils/space";
import {CodeActionProvider} from "./utils/code_action";
import {insertSnippet} from "./utils/insert_snippet";

export function deactivate() { }

function SpaceX() {
const editorX = vscode.window.activeTextEditor;
if (editorX && editorX.options.insertSpaces) {
return " ".repeat(<number>editorX.options.tabSize);
}
return "\t";
}

export class CodeActionProvider implements vscode.CodeActionProvider {
public provideCodeActions(): vscode.Command[] {
const editorX = vscode.window.activeTextEditor;
if (!editorX || editorX.selection.isEmpty) {
return [];
}
const pickedText = editorX.document.getText(editorX.selection);

const codeActions = [];
if (pickedText !== '') {
codeActions.push({
command: "get.wrapInGetx",
title: "Wrap with GetX"
});
codeActions.push({
command: "get.wrapInGetBuilder",
title: "Wrap with GetBuilder"
});
codeActions.push({
command: "get.wrapInObx",
title: "Wrap with Obx"
});
}
return codeActions;
}
}

function insertSnippet(
previously: string,
behind: string,
spacex: string,
substitute?: boolean | false,
obx?: boolean | false
) {
const editorX = vscode.window.activeTextEditor;

if (editorX && editorX.selection.start !== editorX.selection.end) {
var choice = editorX.selection;
var sonny = editorX.document.getText(choice).trimLeft();
var line = editorX.document.lineAt(choice.start);
sonny = sonny.replace(
new RegExp("\n\\s{" + line.firstNonWhitespaceCharacterIndex + "}", "gm"),
"\n" + spacex
);
if (substitute) {
if (sonny.substr(-1) === ",") {
sonny = sonny.substr(0, sonny.length - 1);
sonny += "";
}
}
else {
if (sonny.substr(-1) === ",") {
sonny = sonny.substr(0, sonny.length - 1);
sonny += ";";
}
}
var replaceSonny = previously + sonny + behind;
if (
sonny.substr(-1) === "," ||
(sonny.substr(-1) === ";" && substitute)
) {

if (obx) {
replaceSonny += ";";
} else {
replaceSonny += ",";
}

}
editorX.insertSnippet(new vscode.SnippetString(replaceSonny), choice);
}
}

export const activate = (context: vscode.ExtensionContext) => {

context.subscriptions.push(
Expand All @@ -97,24 +18,48 @@ export const activate = (context: vscode.ExtensionContext) => {
vscode.commands.registerCommand(
"get.wrapInGetx",
() => {
insertSnippet("GetX<${1:My}Controller>(\n" + SpaceX() + "init: ${1:My}Controller(),\n" + SpaceX() + "initState: (_) {},\n" + SpaceX() + "builder: (_) {\n" + SpaceX() + SpaceX() + "return ", "\n },\n" + "),", SpaceX(), false, false);
insertSnippet("GetX<${1:My}Controller>(\n" + SpaceX() + "init: ${1:My}Controller(),\n" + SpaceX() + "initState: (_) {},\n" + SpaceX() + "builder: (_) {\n" + SpaceX() + SpaceX() + "return ", "; \n },\n" + ")", SpaceX(), false, false);

vscode.window.setStatusBarMessage("Wrap Successfully Created", 2000);
})
);

context.subscriptions.push(
vscode.commands.registerCommand(
"get.wrapInGetBuilder",
() => {
insertSnippet("GetBuilder<${1:My}Controller>(\n" + SpaceX() + "init: ${1:My}Controller(),\n" + SpaceX() + "initState: (_) {},\n" + SpaceX() + "builder: (_) {\n" + SpaceX() + SpaceX() + "return ", "\n },\n" + "),", SpaceX(), false, false);
insertSnippet("GetBuilder<${1:My}Controller>(\n" + SpaceX() + "init: ${1:My}Controller(),\n" + SpaceX() + "initState: (_) {},\n" + SpaceX() + "builder: (_) {\n" + SpaceX() + SpaceX() + "return ", "; \n },\n" + ")", SpaceX(), false, false);

vscode.window.setStatusBarMessage("Wrap Successfully Created", 2000);
})
);

context.subscriptions.push(
vscode.commands.registerCommand(
"get.wrapInObx",
() => {
insertSnippet("Obx(() =>" + " ", "),", SpaceX(), true, true);
insertSnippet("Obx(() =>" + " ", ")", SpaceX(), true, true);

vscode.window.setStatusBarMessage("Wrap Successfully Created", 2000);

})
);

context.subscriptions.push(
vscode.commands.registerCommand(
"get.removeKey",
() => {

vscode.window.showWarningMessage('You can now use the lamp by clicking on the name of the widget. The shortcut keys have been disabled.', ...['OK', 'Readme Snippets'])
.then(selection => {
if (selection === "Readme Snippets") {
vscode.env.openExternal(vscode.Uri.parse(
'https://marketplace.visualstudio.com/items?itemName=get-snippets.get-snippets'));
}
});

})
);


};
};
Loading

0 comments on commit 5ce7090

Please sign in to comment.