diff --git a/src/renderer/components/ReplaceAllButton.jsx b/src/renderer/components/ReplaceAllButton.jsx index e410161..b4c49c5 100644 --- a/src/renderer/components/ReplaceAllButton.jsx +++ b/src/renderer/components/ReplaceAllButton.jsx @@ -5,14 +5,14 @@ import { EVENT_RUN_SNIPPET, REPLACE_ALL_TEST_RESULTS, SET_LOADING } from "../con import { triggerEvent } from "../utils"; const ReplaceAllButton = () => { - const { language, rootPath, onlyPaths, skipPaths, snippetCode, testResults, dispatch } = useContext(AppContext); + const { language, rootPath, onlyPaths, skipPaths, respectGitignore, snippetCode, testResults, dispatch } = useContext(AppContext); const replace = () => { if (testResults.length > 0) { dispatch({ type: REPLACE_ALL_TEST_RESULTS, testResults, rootPath }); } else { dispatch({ type: SET_LOADING, loading: true, loadingText: "Running... it may take a while" }); - triggerEvent(EVENT_RUN_SNIPPET, { language, rootPath, snippetCode, onlyPaths, skipPaths }); + triggerEvent(EVENT_RUN_SNIPPET, { language, rootPath, snippetCode, onlyPaths, skipPaths, respectGitignore }); } }; diff --git a/src/renderer/components/RespectGitignoreCheckbox.jsx b/src/renderer/components/RespectGitignoreCheckbox.jsx new file mode 100644 index 0000000..4bf5fee --- /dev/null +++ b/src/renderer/components/RespectGitignoreCheckbox.jsx @@ -0,0 +1,27 @@ +import React, { useContext, useEffect, useState } from "react"; + +import AppContext from "../context"; +import { SET_RESPECT_GITIGNORE } from "../constants"; +import { saveRespectGitignore } from "../utils"; + +const RespectGitignoreCheckbox = () => { + const { respectGitignore, dispatch } = useContext(AppContext); + const [value, setValue] = useState(respectGitignore); + + useEffect(() => setValue(respectGitignore), [respectGitignore]); + + const handleValueChanged = (event) => { + const respectGitignore = event.target.checked; + dispatch({ type: SET_RESPECT_GITIGNORE, respectGitignore }); + saveRespectGitignore(respectGitignore); + }; + + return ( + + ); +}; + +export default RespectGitignoreCheckbox; diff --git a/src/renderer/components/RunSnippet.jsx b/src/renderer/components/RunSnippet.jsx index 6f8e428..8373eec 100644 --- a/src/renderer/components/RunSnippet.jsx +++ b/src/renderer/components/RunSnippet.jsx @@ -6,6 +6,7 @@ import { EVENT_SNIPPET_RUN, SET_LOADING } from "../constants"; import WorkingDir from "./WorkingDir"; import FilesToInclude from "./FilesToInclude"; import FilesToExclude from "./FilesToExclude"; +import RespectGitignoreCheckbox from "./RespectGitIgnoreCheckbox"; import SearchButton from "./SearchButton"; import ReplaceAllButton from "./ReplaceAllButton"; import { showMessage } from "../utils"; @@ -29,7 +30,8 @@ export default () => {
-
+
+
diff --git a/src/renderer/components/SearchButton.jsx b/src/renderer/components/SearchButton.jsx index e24aada..2a01f84 100644 --- a/src/renderer/components/SearchButton.jsx +++ b/src/renderer/components/SearchButton.jsx @@ -5,11 +5,11 @@ import { EVENT_TEST_SNIPPET, SET_LOADING } from "../constants"; import { triggerEvent } from "../utils"; const SearchButton = () => { - const { language, rootPath, onlyPaths, skipPaths, snippetCode, dispatch } = useContext(AppContext); + const { language, rootPath, onlyPaths, skipPaths, respectGitignore, snippetCode, dispatch } = useContext(AppContext); const search = () => { dispatch({ type: SET_LOADING, loading: true, loadingText: "Searching... it may take a while" }); - triggerEvent(EVENT_TEST_SNIPPET, { language, rootPath, snippetCode, onlyPaths, skipPaths }); + triggerEvent(EVENT_TEST_SNIPPET, { language, rootPath, snippetCode, onlyPaths, skipPaths, respectGitignore }); }; return ( diff --git a/src/renderer/constants.js b/src/renderer/constants.js index 8e4e04f..dc5ecbe 100644 --- a/src/renderer/constants.js +++ b/src/renderer/constants.js @@ -33,9 +33,11 @@ export const SET_CURRENT_ACTION_INDEX = "SET_CURRENT_ACTION_INDEX"; export const SET_ROOT_PATH = "SET_ROOT_PATH"; export const SET_ONLY_PATHS = "SET_ONLY_PATHS"; export const SET_SKIP_PATHS = "SET_SKIP_PATHS"; +export const SET_RESPECT_GITIGNORE = "SET_RESPECT_GITIGNORE"; export const LANGUAGE = "language"; export const PARSER = "parser"; export const ROOT_PATH = "root_path"; export const ONLY_PATHS = "only_paths"; export const SKIP_PATHS = "skip_paths"; +export const RESPECT_GITIGNORE = "respect_gitignore"; diff --git a/src/renderer/index.css b/src/renderer/index.css index 777295e..44568d0 100644 --- a/src/renderer/index.css +++ b/src/renderer/index.css @@ -72,7 +72,7 @@ button.close:hover { .new-snippet .nql-or-rules-select label { margin-right: 10px; } -.new-snippet .nql-or-rules-select input[type="radio"] { +input[type="radio"], input[type="checkbox"] { margin-right: 5px; } diff --git a/src/renderer/provider.js b/src/renderer/provider.js index 0232f8b..b108e93 100644 --- a/src/renderer/provider.js +++ b/src/renderer/provider.js @@ -4,7 +4,7 @@ import { useReducerAsync } from "use-reducer-async"; import appReducer from "./reducer"; import appAction from "./action"; import AppContext from "./context"; -import { getInited, getLanguage, getOnlyPaths, getRootPath, getSkipPaths } from "./utils"; +import { getInited, getLanguage, getOnlyPaths, getRootPath, getSkipPaths, getRespectGitignore } from "./utils"; const initialState = { inited: getInited(), @@ -12,6 +12,7 @@ const initialState = { rootPath: getRootPath(), onlyPaths: getOnlyPaths(), skipPaths: getSkipPaths(), + respectGitignore: getRespectGitignore() === false ? false : true, snippetsStore: {}, currentSnippetId: null, generatedSnippets: [], diff --git a/src/renderer/reducer.js b/src/renderer/reducer.js index 543f0e5..d877015 100644 --- a/src/renderer/reducer.js +++ b/src/renderer/reducer.js @@ -13,6 +13,7 @@ import { SET_ROOT_PATH, SET_ONLY_PATHS, SET_SKIP_PATHS, + SET_RESPECT_GITIGNORE, SET_LANGUAGE, SET_PARSER, SET_INITED, @@ -156,6 +157,7 @@ export default (state = {}, action) => { rootPath: action.rootPath, onlyPaths: action.onlyPaths, skipPaths: action.skipPaths, + respectGitignore: action.respectGitignore, }; } case SET_ONLY_PATHS: { @@ -170,6 +172,12 @@ export default (state = {}, action) => { skipPaths: action.skipPaths, }; } + case SET_RESPECT_GITIGNORE: { + return { + ...state, + respectGitignore: action.respectGitignore, + }; + } default: return state; } diff --git a/src/renderer/renderer.js b/src/renderer/renderer.js index 7ced67c..b3e1f44 100644 --- a/src/renderer/renderer.js +++ b/src/renderer/renderer.js @@ -199,7 +199,7 @@ const testSnippet = async (event) => { return; } const { - detail: { snippetCode, rootPath, onlyPaths, skipPaths }, + detail: { snippetCode, rootPath, onlyPaths, skipPaths, respectGitignore }, } = event; const additionalArgs = buildAdditionalCommandArgs(language); const synvertCommand = language === "ruby" ? runSynvertRuby : runSynvertJavascript; @@ -210,6 +210,7 @@ const testSnippet = async (event) => { rootPath, onlyPaths, skipPaths, + respectGitignore, additionalArgs, snippetCode, binPath, @@ -237,7 +238,7 @@ const runSnippet = async (event) => { return; } const { - detail: { snippetCode, rootPath, onlyPaths, skipPaths }, + detail: { snippetCode, rootPath, onlyPaths, skipPaths, respectGitignore }, } = event; const additionalArgs = buildAdditionalCommandArgs(language); const synvertCommand = language === "ruby" ? runSynvertRuby : runSynvertJavascript; @@ -248,6 +249,7 @@ const runSnippet = async (event) => { rootPath, onlyPaths, skipPaths, + respectGitignore, additionalArgs, snippetCode, binPath, diff --git a/src/renderer/utils.js b/src/renderer/utils.js index 5daff4f..378d754 100644 --- a/src/renderer/utils.js +++ b/src/renderer/utils.js @@ -1,7 +1,7 @@ import React from "react"; import toast from "react-hot-toast"; -import { ROOT_PATH, ONLY_PATHS, SKIP_PATHS, LANGUAGE, LANGUAGES, PARSER } from "./constants"; +import { ROOT_PATH, ONLY_PATHS, SKIP_PATHS, RESPECT_GITIGNORE, LANGUAGE, LANGUAGES, PARSER } from "./constants"; const CUSTOM = "custom"; export const DEFAULT_VALUES = { @@ -62,7 +62,7 @@ const getPreference = (section, key) => { if (!preferences[section]) { preferences[section] = {}; } - return preferences[section][key] || DEFAULT_VALUES[section][key]; + return preferences[section][key] === undefined ? DEFAULT_VALUES[section][key] : preferences[section][key]; }; export const saveInited = (inited) => savePreference(CUSTOM, "inited", inited); @@ -126,6 +126,9 @@ export const saveOnlyPaths = (path) => savePreference(CUSTOM, getRootPath() + ": export const getSkipPaths = () => getPreference(CUSTOM, getRootPath() + ":" + SKIP_PATHS) || ""; export const saveSkipPaths = (path) => savePreference(CUSTOM, getRootPath() + ":" + SKIP_PATHS, path); +export const getRespectGitignore = () => getPreference(CUSTOM, getRootPath() + ":" + RESPECT_GITIGNORE); +export const saveRespectGitignore = (respectGitignore) => savePreference(CUSTOM, getRootPath() + ":" + RESPECT_GITIGNORE, respectGitignore); + export const convertSnippetsToStore = (snippets) => snippets.reduce( (obj, snippet) => ({