Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #79 add search bar for page list view #150

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/pencil-core/common/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ Controller.prototype.removeRecentFile = function (filePath) {
};
Controller.prototype.loadDocument = function (filePath, callback) {
ApplicationPane._instance.busy();
this.applicationPane.pageListView.restartFilterCache();
this.resetDocument();
var thiz = this;
if (!fs.existsSync(filePath)) {
Expand Down
100 changes: 97 additions & 3 deletions app/views/common/PageListView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
function PageListView() {
BaseTemplatedWidget.call(this);

this.filterCache = {};
this.showFilterBar = false;

var findPageThumbnailView = function (event) {
var node = Dom.findUpward(event.target, function (n) {
return n.__widget && (n.__widget instanceof PageThumbnailView);
Expand All @@ -21,7 +24,6 @@ function PageListView() {

}, this.pageListContainer);


// this.bind("mouseover", function (event) {
// var page = Dom.findUpwardForData(event.target, "_page");
// if(!page || page.children.length == 0) return;
Expand Down Expand Up @@ -79,7 +81,6 @@ function PageListView() {
}
}
}

this.activatePage(newActivePage);
}, this.pageBreadcrumb);

Expand Down Expand Up @@ -128,8 +129,34 @@ function PageListView() {
this.pageListSrollView.invalidate();
this.childPageSrollView.invalidate();
Config.set("pageListViewExpanded.enabled", this.expanded);
this.validateFilterBox();
this.filterPages();
}, this.toggleButton);

this.bind("click", function(ev) {
this.showFilterBar = !this.showFilterBar;
this.validateFilterBox();
},this.filterButton);

this.bind("input", function(ev) {
setTimeout(function() {
var value = thiz.nameTextBox.value == "" ? null : thiz.nameTextBox.value;
var filterName = thiz.controller.activePage.parentPage ? thiz.controller.activePage.parentPage.name : "Root";
if (value == null && thiz.filterCache[filterName] != null) {
delete thiz.filterCache[filterName];
} else {
thiz.filterCache[filterName] = value;
}
thiz.filterPages();
thiz.nameTextBox.focus();
}, 500);
}, this.nameTextBox)

this.bind("blur", function(ev) {
this.showFilterBar = false;
this.validateFilterBox();
}, this.nameTextBox)

this.pageListContainer._isDropZone = true;
this.childPageContainer._isDropZone = true;

Expand Down Expand Up @@ -214,6 +241,70 @@ function PageListView() {
this.invalidateExpandedState();
}
__extend(BaseTemplatedWidget, PageListView);

PageListView.prototype.restartFilterCache = function() {
this.filterCache = {};
}

PageListView.prototype.validateFilterBox = function() {
if (this.showFilterBar == true) {
this.filterContainer.style.display = "flex";
var filterName = this.controller.activePage.parentPage ? this.controller.activePage.parentPage.name : "Root";
if (this.filterCache[filterName]) {
this.nameTextBox.value = this.filterCache[filterName] == null ? "" : this.filterCache[filterName];
}
var bottom = this.controller.applicationPane.pageListView.node().clientHeight;
var right = this.controller.applicationPane.rightSidePane.node().clientWidth;
this.filterContainer.style.bottom = (bottom + 5) + "px";
this.filterContainer.style.right = (right + 5) + "px";
this.filterButton.disabled = true;
var thiz = this;
window.setTimeout(function() {
thiz.nameTextBox.focus();
}, 0)
} else {
this.filterButton.disabled = false;
this.filterContainer.style.display = "none";
}
}

PageListView.prototype.filterPages = function() {
var filterName = this.controller.activePage.parentPage ? this.controller.activePage.parentPage.name : "Root";
var value = this.filterCache[filterName];

if (!value) {
this.filterValue.innerHTML = "Filter";
this.nameTextBox.value = "";
Dom.removeClass(this.filterButton, "activeFilter");
} else {
this.nameTextBox.value = value;
this.filterValue.innerHTML = value;
Dom.addClass(this.filterButton, "activeFilter");
}
var selectedContainer = this.expanded == true ? this.pageListContainer : this.childPageContainer;
var hiddenItemCount = 0;
for (var i = 0; i < selectedContainer.childNodes.length; i++) {
var item = selectedContainer.childNodes[i];
var activePageItem;
var page;
if (this.expanded) page = item.__widget.page;
else page = item._page;
item.style.display = "inherit";
if (value) {
if (page.name.toUpperCase().indexOf(value.toUpperCase()) < 0) {
hiddenItemCount++;
item.style.display = "none";
}
if (page == this.controller.activePage) {
activePageItem = item;
}
}
}
// if (hiddenItemCount == selectedContainer.childNodes.length) {
// activePageItem.style.display = "inherit";
// }
}

PageListView.prototype.setController = function (controller) {
this.controller = controller;
this.currentParentPage = null;
Expand Down Expand Up @@ -384,9 +475,9 @@ PageListView.prototype.renderPages = function() {
this.childPageContainer.appendChild(childNode);
}
this.invalidateExpandedState();

this.childPageSrollView.invalidate();
this.pageListSrollView.invalidate();

var thiz = this;
window.setTimeout(function () {
var childListFrom = 0;
Expand Down Expand Up @@ -415,7 +506,9 @@ PageListView.prototype.renderPages = function() {
}
thiz.childPageSrollView.ensuareVisible(childListFrom, childListTo);
thiz.pageListSrollView.ensuareVisible(thumbnailFrom, thumbnailTo);
thiz.filterPages();
}, 0);

};

PageListView.prototype.invalidateExpandedState = function() {
Expand Down Expand Up @@ -453,6 +546,7 @@ PageListView.prototype.handleDoubleClick = function (page) {
if (!page.children || page.children.length == 0) {
this.handleSelectPage(page);
} else {
if (this.filterCache[page.name]) delete this.filterCache[page.name];
this.activatePage(page.children[0]);
}
};
65 changes: 56 additions & 9 deletions app/views/common/PageListView.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
border: solid 1px;
border-color: lighten(@app_bg, 5%) darken(@app_bg, 10%) darken(@app_bg, 10%) lighten(@app_bg, 5%);
}
@header {
@header,
@filterContainer {
background: @app_bg;
align-items: center;
padding-right: 0.3em;
position: relative;
overflow: visible;
min-height: 2.8em;
}

@filterContainer {
padding: 3px;
}

@header .widget_ScrollableView > button,
@header button {
@header button,
@filterContainer button {
line-height: 1.4em;
height: 1.4em;
padding: 0em 0.3em;
Expand All @@ -22,7 +29,8 @@

@pageBreadcrumb button:not(:hover),
@actionButtonContainer button:not(:hover),
@pageBreadcrumb > hbox:last-child button {
@pageBreadcrumb > hbox:last-child button,
@filterContainer button:not(:hover) {
background: none;
border-color: transparent;
}
Expand Down Expand Up @@ -65,13 +73,16 @@
margin-left: 0.4em;
}

@pageBreadcrumb {
@pageBreadcrumb,
@nameTextBoxContainer {
white-space: nowrap;
}

@pageBreadcrumb,
@childPageContainer {
@childPageContainer,
@nameTextBoxContainer {
cursor: default;
min-height: 1.8em;
}
@childPageSrollView {
background: #FFF;
Expand All @@ -84,7 +95,8 @@
@iconify();
}
@pageBreadcrumb > hbox,
@childPageContainer > hbox {
@childPageContainer > hbox,
@nameTextBoxContainer > hbox {
line-height: 1.6em;
position: relative;
}
Expand All @@ -105,7 +117,9 @@
@childPageContainer > hbox:hover {
color: @selected_bg;
}
@pageBreadcrumb > hbox > span {


@pageBreadcrumb > hbox > span{
padding: 0em 0.5em;
cursor: pointer;
}
Expand All @@ -116,7 +130,8 @@
text-decoration: underline;
}
@pageBreadcrumb > hbox,
@childPageContainer > hbox {
@childPageContainer > hbox,
@nameTextBoxContainer{
align-items: center;

}
Expand All @@ -125,7 +140,8 @@
font-size: 1em;
}
@pageBreadcrumb hbox span,
@childPageContainer hbox span {
@childPageContainer hbox span,
@nameTextBoxContainer {
text-align: center;
}

Expand Down Expand Up @@ -225,7 +241,37 @@
display: none;
}

@nameTextBox {
height: 2em;
box-shadow: inset 0px 0px 0.3em rgba(0, 0, 0, 0.2);
border: solid 1px #bfbfbf;
border-radius: 0px;
width: 100%;
}

@filterContainer{
display: none;
position: absolute;
border-radius: 2px;
background: #D3DADE;
padding: 5px;
}
@filterValue {
text-overflow: ellipsis;
overflow: hidden;
max-width: 5em;
white-space: nowrap;
}
@actionButtonContainer .activeFilter {
background: silver !important;
font-weight: bold;

}

</style>
<hbox anon-id="filterContainer">
<hbox flex="1" ><input type="text" anon-id="nameTextBox" /></hbox>
</hbox>
<hbox anon-id="header">
<hbox flex="1">
<hbox anon-id="pageBreadcrumb">
Expand All @@ -240,6 +286,7 @@
</hbox>
</hbox>
<hbox anon-id="actionButtonContainer">
<hbox><button anon-id="filterButton"><i>filter_list</i><span anon-id="filterValue">Filter</span></button></hbox>
<hbox><button anon-id="addPageButton"><i>note_add</i> <span>Add Page...</span></button></hbox>
<hbox><button anon-id="toggleButton"><i>expand_more</i><i>expand_less</i></button></hbox>
</hbox>
Expand Down