Skip to content

Commit

Permalink
Fix neighbouring submenus nesting when they should not
Browse files Browse the repository at this point in the history
  • Loading branch information
gyng committed Aug 5, 2018
1 parent 95aac57 commit eeb1fc3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.1.1

* Fix neighbouring submenus nesting when they should not

# 3.1.0

* Add nl localisation (Thanks @80486dx, #72)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "3.1.0",
"version": "3.1.1",
"default_locale": "en",

"applications": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "save-in",
"version": "3.1.0",
"version": "3.1.1",
"license": "MIT",
"scripts": {
"build": "env -u WEB_EXT_API_KEY -u WEB_EXT_API_SECRET web-ext build --overwrite-dest -i test docs yarn.lock yarn-error.log",
Expand Down
64 changes: 33 additions & 31 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,46 @@ window.init = () => {
filenamePatterns: []
};

OptionsManagement.loadOptions().then(() => {
Notification.addNotifications({
notifyOnSuccess: options.notifyOnSuccess,
notifyOnFailure: options.notifyOnFailure,
notifyDuration: options.notifyDuration,
promptOnFailure: options.promptOnFailure
});
OptionsManagement.loadOptions()
.then(browser.contextMenus.removeAll())
.then(() => {
Notification.addNotifications({
notifyOnSuccess: options.notifyOnSuccess,
notifyOnFailure: options.notifyOnFailure,
notifyDuration: options.notifyDuration,
promptOnFailure: options.promptOnFailure
});

const pathsArray = options.paths
.split("\n")
.map(p => p.trim())
.filter(p => p && p.length > 0);
const pathsArray = options.paths
.split("\n")
.map(p => p.trim())
.filter(p => p && p.length > 0);

let contexts = options.links ? MEDIA_TYPES.concat(["link"]) : MEDIA_TYPES;
contexts = options.selection ? contexts.concat(["selection"]) : contexts;
contexts = options.page ? contexts.concat(["page"]) : contexts;
let contexts = options.links ? MEDIA_TYPES.concat(["link"]) : MEDIA_TYPES;
contexts = options.selection ? contexts.concat(["selection"]) : contexts;
contexts = options.page ? contexts.concat(["page"]) : contexts;

Menus.addTabMenus();
Menus.addTabMenus();

if (options.routeExclusive) {
Menus.addRouteExclusive(contexts);
return;
} else {
Menus.addRoot(contexts);
}
if (options.routeExclusive) {
Menus.addRouteExclusive(contexts);
return;
} else {
Menus.addRoot(contexts);
}

if (options.enableLastLocation) {
Menus.addLastUsed(contexts);
Menus.makeSeparator(contexts);
}
if (options.enableLastLocation) {
Menus.addLastUsed(contexts);
Menus.makeSeparator(contexts);
}

Menus.addPaths(pathsArray, contexts);
Menus.makeSeparator(contexts);
Menus.addPaths(pathsArray, contexts);
Menus.makeSeparator(contexts);

Menus.addSelectionType(contexts);
Menus.addShowDefaultFolder(contexts);
Menus.addOptions(contexts);
});
Menus.addSelectionType(contexts);
Menus.addShowDefaultFolder(contexts);
Menus.addOptions(contexts);
});
};

Menus.addDownloadListener();
Expand Down
19 changes: 14 additions & 5 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ const Menus = {
let pathsNestingStack = [];
let lastDepth = 0;

// TODO: Refactor this
// 1. Make a pass to parse dir types
// 2. Parse comments
// 3. Parse depth
// 4. Construct menu items
pathsArray.forEach(dir => {
// HACK
if (dir === SPECIAL_DIRS.SEPARATOR) {
Expand All @@ -234,15 +239,19 @@ const Menus = {
}
const id = `save-in-${menuItemCounter[depth]}-${comment}-${parsedDir}`;

const parentId =
(depth > pathsNestingStack.length
? pathsNestingStack[pathsNestingStack.length - 1]
: pathsNestingStack[depth - 1]) || Menus.IDS.ROOT;
let parentId;
if (depth === 0) {
parentId = Menus.IDS.ROOT;
} else if (depth > pathsNestingStack.length) {
parentId = pathsNestingStack[pathsNestingStack.length - 1];
} else {
parentId = pathsNestingStack[depth - 1];
}

if (depth === 0) {
pathsNestingStack = [id];
} else if (depth === lastDepth) {
pathsNestingStack[depth - 1] = id;
pathsNestingStack[depth] = id;
} else if (depth > lastDepth) {
pathsNestingStack.push(id);
}
Expand Down

0 comments on commit eeb1fc3

Please sign in to comment.