Skip to content

Commit b2bd89e

Browse files
committed
chore: simplilfy recent projects dropdown impl
1 parent d40e75c commit b2bd89e

File tree

3 files changed

+23
-67
lines changed

3 files changed

+23
-67
lines changed

src/extensionsIntegrated/RecentProjects/htmlContent/projects-menu.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<a class="recent-folder-link" data-path="{{path}}">
1414
<span class="recent-folder">{{folder}}</span>
1515
<span class="recent-folder-path">{{rest}}</span>
16+
<div class='trash-icon recent-project-delete'>&times;</div>
1617
</a>
1718
</li>
1819
{{/projectList}}

src/extensionsIntegrated/RecentProjects/main.js

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,6 @@ define(function (require, exports, module) {
9595
PreferencesManager.setViewState(RECENT_PROJECT_STATE, recentProjects);
9696
}
9797

98-
/**
99-
* Check the list of items to see if any of them are hovered, and if so trigger a mouseenter.
100-
* Normally the mouseenter event handles this, but when a previous item is deleted and the next
101-
* item moves up to be underneath the mouse, we don't get a mouseenter event for that item.
102-
*/
103-
function checkHovers(pageX, pageY) {
104-
$dropdown.children().each(function () {
105-
var offset = $(this).offset(),
106-
width = $(this).outerWidth(),
107-
height = $(this).outerHeight();
108-
109-
if (pageX >= offset.left && pageX <= offset.left + width &&
110-
pageY >= offset.top && pageY <= offset.top + height) {
111-
$(".recent-folder-link", this).triggerHandler("mouseenter");
112-
}
113-
});
114-
}
115-
11698
function removeFromRecentProject(fullPath) {
11799
fullPath = FileUtils.stripTrailingSlash(fullPath);
118100
let recentProjects = getRecentProjects(),
@@ -127,44 +109,6 @@ define(function (require, exports, module) {
127109
PreferencesManager.setViewState(RECENT_PROJECT_STATE, newProjects);
128110
}
129111

130-
/**
131-
* Create the "delete" button that shows up when you hover over a project.
132-
*/
133-
function renderDelete() {
134-
return $("<div id='recent-folder-delete' class='trash-icon'>&times;</div>")
135-
.mouseup(function (e) {
136-
// Don't let the click bubble upward.
137-
e.stopPropagation();
138-
139-
// Remove the project from the preferences.
140-
removeFromRecentProject($(this).parent().data("path"));
141-
$(this).closest("li").remove();
142-
checkHovers(e.pageX, e.pageY);
143-
144-
if (getRecentProjects().length === 1) {
145-
$dropdown.find(".divider").remove();
146-
}
147-
});
148-
}
149-
150-
/**
151-
* Hide the delete button.
152-
*/
153-
function removeDeleteButton() {
154-
$("#recent-folder-delete").remove();
155-
}
156-
157-
/**
158-
* Show the delete button over a given target.
159-
*/
160-
function addDeleteButton($target) {
161-
removeDeleteButton();
162-
renderDelete()
163-
.css("top", $target.position().top + 6)
164-
.appendTo($target);
165-
}
166-
167-
168112
/**
169113
* Selects the next or previous item in the list
170114
* @param {number} direction +1 for next, -1 for prev
@@ -190,7 +134,6 @@ define(function (require, exports, module) {
190134
$newItem.addClass("selected");
191135

192136
$dropdownItem = $newItem;
193-
removeDeleteButton();
194137
}
195138

196139
let searchStr ="";
@@ -247,7 +190,6 @@ define(function (require, exports, module) {
247190
// remove project
248191
recentProjects.splice(index, 1);
249192
PreferencesManager.setViewState(RECENT_PROJECT_STATE, recentProjects);
250-
checkHovers(e.pageX, e.pageY);
251193

252194
if (recentProjects.length === 1) {
253195
$dropdown.find(".divider").remove();
@@ -374,6 +316,18 @@ define(function (require, exports, module) {
374316
*/
375317
function _handleListEvents() {
376318
$dropdown
319+
.on("click", ".recent-project-delete", function (e) {
320+
// Don't let the click bubble upward.
321+
e.stopPropagation();
322+
323+
// Remove the project from the preferences.
324+
removeFromRecentProject($(this).parent().data("path"));
325+
$(this).closest("li").remove();
326+
327+
if (getRecentProjects().length === 1) {
328+
$dropdown.find(".divider").remove();
329+
}
330+
})
377331
.on("click", "a", function () {
378332
var $link = $(this),
379333
id = $link.attr("id"),
@@ -397,22 +351,13 @@ define(function (require, exports, module) {
397351
$dropdownItem.removeClass("selected");
398352
}
399353
$dropdownItem = $(this).addClass("selected");
400-
401-
if ($dropdownItem.hasClass("recent-folder-link")) {
402-
// Note: we can't depend on the event here because this can be triggered
403-
// manually from checkHovers().
404-
addDeleteButton($(this));
405-
}
406354
})
407355
.on("mouseleave", "a", function () {
408356
var $link = $(this).removeClass("selected");
409357

410358
if ($link.get(0) === $dropdownItem.get(0)) {
411359
$dropdownItem = null;
412360
}
413-
if ($link.hasClass("recent-folder-link")) {
414-
removeDeleteButton();
415-
}
416361
});
417362
}
418363

src/styles/Extn-RecentProjects.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@
9999

100100
#project-dropdown.dropdown-menu li a {
101101
padding: 5px 15px;
102+
position: relative;
103+
}
104+
105+
.recent-project-delete {
106+
visibility: hidden;
107+
}
108+
109+
.recent-folder-link:hover > .recent-project-delete {
110+
top: 26%;
111+
visibility: visible;
102112
}
103113

104114
#project-dropdown.dropdown-menu .recent-folder-link, #project-dropdown.dropdown-menu #open-folder-link #new-project-link #download-project-link{

0 commit comments

Comments
 (0)