Skip to content

Commit

Permalink
feat: ES-141 add shortcut for app settings
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasdaloia committed Mar 6, 2025
1 parent 67e20a7 commit 93559b3
Show file tree
Hide file tree
Showing 10 changed files with 298 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ go_lint_docker: ## Run docker instance of Go linting across the code base

run: cp_assets ## Runs the application in development mode
$(eval APPARGS := $(ARGS))
@wails dev -ldflags "-X github.com/scanoss/scanoss.cc/backend/entities.AppVersion=$(VERSION)" $(if $(strip $(APPARGS)),-appargs "$(APPARGS)")
@wails dev -ldflags "-X github.com/scanoss/scanoss.cc/backend/entities.AppVersion=$(VERSION)" $(if $(strip $(APPARGS)),-appargs "--debug $(APPARGS)")

npm: ## Install NPM dependencies for the frontend
@echo "Running npm install for frontend..."
Expand Down
10 changes: 6 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (a *App) initializeMenu() {
groupedShortcuts := a.keyboardService.GetGroupedShortcuts()
actionShortcuts := groupedShortcuts[entities.GroupActions]
globalShortcuts := groupedShortcuts[entities.GroupGlobal]

viewShortcuts := groupedShortcuts[entities.GroupView]
// Global edit menu
EditMenu := AppMenu.AddSubmenu("Edit")
for _, shortcut := range globalShortcuts {
Expand All @@ -133,9 +133,11 @@ func (a *App) initializeMenu() {

// View menu
ViewMenu := AppMenu.AddSubmenu("View")
ViewMenu.AddText("Sync Scroll Position", keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey), func(cd *menu.CallbackData) {
runtime.EventsEmit(a.ctx, string(entities.ActionToggleSyncScrollPosition))
})
for _, shortcut := range viewShortcuts {
ViewMenu.AddText(shortcut.Name, shortcut.Accelerator, func(cd *menu.CallbackData) {
runtime.EventsEmit(a.ctx, string(shortcut.Action))
})
}

// Scan menu
ScanMenu := AppMenu.AddSubmenu("Scan")
Expand Down
12 changes: 11 additions & 1 deletion backend/entities/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (
// View
ActionToggleSyncScrollPosition Action = "toggleSyncScrollPosition"
ActionShowKeyboardShortcutsModal Action = "showKeyboardShortcutsModal"

ActionOpenSettings Action = "openSettings"
// Scan
ActionScanWithOptions Action = "scanWithOptions"
)
Expand Down Expand Up @@ -108,6 +108,7 @@ var AllShortcutActions = []struct {
{ActionToggleSyncScrollPosition, "ToggleSyncScrollPosition"},
{ActionShowKeyboardShortcutsModal, "ShowKeyboardShortcutsModal"},
{ActionScanWithOptions, "ScanWithOptions"},
{ActionOpenSettings, "OpenSettings"},
}

var DefaultShortcuts = []Shortcut{
Expand Down Expand Up @@ -291,6 +292,7 @@ var DefaultShortcuts = []Shortcut{
Action: ActionReplaceComponentWithComments,
},

// View
{
Name: "Sync Scroll Position",
Description: "Sync the scroll position of the editors",
Expand All @@ -299,6 +301,14 @@ var DefaultShortcuts = []Shortcut{
Group: GroupView,
Action: ActionToggleSyncScrollPosition,
},
{
Name: "Settings",
Description: "Open the app settings",
Accelerator: keys.CmdOrCtrl(","),
Keys: "mod+,",
Group: GroupView,
Action: ActionOpenSettings,
},

// Scan
{
Expand Down
209 changes: 209 additions & 0 deletions backend/entities/scanoss_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,212 @@ func (sf *SettingsFile) GetBomEntryFromResult(result Result) ComponentFilter {

return ComponentFilter{}
}

var DefaultSkippedDirs = []string{
"nbproject",
"nbbuild",
"nbdist",
"__pycache__",
"venv",
"_yardoc",
"eggs",
"wheels",
"htmlcov",
"__pypackages__",
"example",
"examples",
"docs",
"tests",
"doc",
"test",
}

var DefaultSkippedFiles = []string{
"gradlew",
"gradlew.bat",
"mvnw",
"mvnw.cmd",
"gradle-wrapper.jar",
"maven-wrapper.jar",
"thumbs.db",
"babel.config.js",
"license.txt",
"license.md",
"copying.lib",
"makefile",
}

var DefaultSkippedDirExtensions = []string{".egg-info"}

var DefaultSkippedExtensions = []string{
".1",
".2",
".3",
".4",
".5",
".6",
".7",
".8",
".9",
".ac",
".adoc",
".am",
".asciidoc",
".bmp",
".build",
".cfg",
".chm",
".class",
".cmake",
".cnf",
".conf",
".config",
".contributors",
".copying",
".crt",
".csproj",
".css",
".csv",
".dat",
".data",
".doc",
".docx",
".dtd",
".dts",
".iws",
".c9",
".c9revisions",
".dtsi",
".dump",
".eot",
".eps",
".geojson",
".gdoc",
".gif",
".glif",
".gmo",
".gradle",
".guess",
".hex",
".htm",
".html",
".ico",
".iml",
".in",
".inc",
".info",
".ini",
".ipynb",
".jpeg",
".jpg",
".json",
".jsonld",
".lock",
".log",
".m4",
".map",
".markdown",
".md",
".md5",
".meta",
".mk",
".mxml",
".o",
".otf",
".out",
".pbtxt",
".pdf",
".pem",
".phtml",
".plist",
".png",
".po",
".ppt",
".prefs",
".properties",
".pyc",
".qdoc",
".result",
".rgb",
".rst",
".scss",
".sha",
".sha1",
".sha2",
".sha256",
".sln",
".spec",
".sql",
".sub",
".svg",
".svn-base",
".tab",
".template",
".test",
".tex",
".tiff",
".toml",
".ttf",
".txt",
".utf-8",
".vim",
".wav",
".woff",
".woff2",
".xht",
".xhtml",
".xls",
".xlsx",
".xml",
".xpm",
".xsd",
".xul",
".yaml",
".yml",
".wfp",
".editorconfig",
".dotcover",
".pid",
".lcov",
".egg",
".manifest",
".cache",
".coverage",
".cover",
".gem",
".lst",
".pickle",
".pdb",
".gml",
".pot",
".plt",
".whml",
".pom",
".smtml",
".min.js",
".mf",
".base64",
".s",
".diff",
".patch",
".rules",
// File endings
"-doc",
"changelog",
"config",
"copying",
"license",
"authors",
"news",
"licenses",
"notice",
"readme",
"swiftdoc",
"texidoc",
"todo",
"version",
"ignore",
"manifest",
"sqlite",
"sqlite3",
}
40 changes: 32 additions & 8 deletions backend/repository/scanoss_settings_repository_json_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ import (
)

type ScanossSettingsJsonRepository struct {
fr utils.FileReader
mutex sync.RWMutex
fr utils.FileReader
mutex sync.RWMutex
defaultSkipPatterns []string
}

func NewScanossSettingsJsonRepository(fr utils.FileReader) ScanossSettingsRepository {
Expand All @@ -58,6 +59,8 @@ func (r *ScanossSettingsJsonRepository) Init() error {
return err
}

r.defaultSkipPatterns = r.generateDefaultSkipPatterns()

r.setSettingsFile(cfg.GetScanSettingsFilePath())

cfg.RegisterListener(r.onConfigChange)
Expand Down Expand Up @@ -244,16 +247,37 @@ func (r *ScanossSettingsJsonRepository) MatchesScanningSkipPattern(path string)
isDir = fileInfo.IsDir()
}

if ps.Match(strings.Split(path, "/"), isDir) {
return true
}

return false
pathParts := strings.Split(path, "/")
return ps.Match(pathParts, isDir)
}

func (r *ScanossSettingsJsonRepository) getScanningSkipPatterns() []string {
sf := r.GetSettings()
return sf.Settings.Skip.Patterns.Scanning
return append(r.defaultSkipPatterns, sf.Settings.Skip.Patterns.Scanning...)
}

func (r *ScanossSettingsJsonRepository) generateDefaultSkipPatterns() []string {
defaultSkipPatterns := make([]string, 0, len(entities.DefaultSkippedDirExtensions)+len(entities.DefaultSkippedExtensions)+len(entities.DefaultSkippedDirs)+len(entities.DefaultSkippedFiles))

for _, dirExtension := range entities.DefaultSkippedDirExtensions {
defaultSkipPatterns = append(defaultSkipPatterns, fmt.Sprintf("*%s", dirExtension))
}

for _, extension := range entities.DefaultSkippedExtensions {
defaultSkipPatterns = append(defaultSkipPatterns, fmt.Sprintf("*%s", extension))
}

for _, dir := range entities.DefaultSkippedDirs {
defaultSkipPatterns = append(defaultSkipPatterns, fmt.Sprintf("%s/", dir))
}

defaultSkipPatterns = append(defaultSkipPatterns, entities.DefaultSkippedFiles...)

return defaultSkipPatterns
}

func (r *ScanossSettingsJsonRepository) GetDefaultSkipPatterns(sf *entities.SettingsFile) []string {
return r.defaultSkipPatterns
}

func (r *ScanossSettingsJsonRepository) AddScanningSkipPattern(pattern string) error {
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/AppSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
*/

import { Settings } from 'lucide-react';
import { useState } from 'react';
import { useEffect, useState } from 'react';

import { entities } from '../../wailsjs/go/models';
import { EventsOn } from '../../wailsjs/runtime/runtime';
import SettingsDialog from './SettingsDialog';
import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip';

Expand All @@ -33,6 +35,12 @@ export default function AppSettings() {
const handleOpenSettingsModal = () => setShowSettingsModal(true);
const handleCloseSettingsModal = () => setShowSettingsModal(false);

useEffect(() => {
EventsOn(entities.Action.OpenSettings, () => {
setShowSettingsModal(true);
});
}, []);

return (
<>
<Tooltip>
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lib/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ export const KEYBOARD_SHORTCUTS: Record<entities.Action, KeyboardShortcut> = {
description: 'Show the keyboard shortcuts modal',
keys: 'mod+shift+k',
},
[entities.Action.OpenSettings]: {
name: 'Open Settings',
description: 'Open the app settings',
keys: 'mod+,',
},

// Scan
[entities.Action.ScanWithOptions]: {
Expand Down
1 change: 1 addition & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export namespace entities {
ToggleSyncScrollPosition = "toggleSyncScrollPosition",
ShowKeyboardShortcutsModal = "showKeyboardShortcutsModal",
ScanWithOptions = "scanWithOptions",
OpenSettings = "openSettings",
}
export class ComponentFilter {
path?: string;
Expand Down
Loading

0 comments on commit 93559b3

Please sign in to comment.