Attempt to improve prefix handling in hint
diff --git a/dev/js/src/hint.js b/dev/js/src/hint.js
index 89003ee..16b3f8b 100644
--- a/dev/js/src/hint.js
+++ b/dev/js/src/hint.js
@@ -9,6 +9,11 @@
* TODO: Sometimes the drop-down box down vanish when list is shown
* TODO: Create should expect an input text field
* TODO: Embed only one single menu (not multiple)
+ * By holding the current menu in _active
+ * TODO: show() should accept a context field (especially for no-context fields,
+ * like fragments)
+ * TODO: Improve context analyzer from hint!
+ * TODO: Marked annotations should be addable to "fragments"
*/
define([
'hint/input',
@@ -70,7 +75,7 @@
// Holds all menus per prefix context
this._menu = {};
this._alert = alertClass.create();
- this._active = false;
+ this._active = null;
// Get input field
var qfield = param["inputField"] || document.getElementById("q-field");
@@ -146,19 +151,19 @@
// Set container to active (aka hide the hint helper button)
this._alert.show(msg);
- this.active(true);
+ this.active(this._alert);
return true;
},
_unshowAlert : function () {
- this._alert.unshow();
- this.active(false);
+ this._alert.hide();
+ this.active(null);
},
update : function () {
this._inputField.update();
- if (this._alert.unshow())
- this.active(false);
+ if (this._alert.hide())
+ this.active(null);
},
@@ -186,29 +191,32 @@
* Get the correct menu based on the context
*/
contextMenu : function (ifContext) {
+
+ // Get context (aka left text)
var context = this._inputField.context();
- if (context === undefined || context.length == 0)
+ if (context === undefined || context.length === 0)
return ifContext ? undefined : this.menu("-");
+ // Get context (aka left text matching regex)
context = this._analyzer.test(context);
if (context === undefined || context.length == 0)
return ifContext ? undefined : this.menu("-");
- return this.menu(context);
+ return this.menu(context) || this.menu('-');
},
- active : function (bool) {
+ active : function (obj) {
if (arguments.length === 1) {
var c = this._inputField.container();
- if (bool && !this._active) {
+ if (obj !== null) {
c.classList.add('active');
- this._active = true;
+ this._active = obj;
}
else {
c.classList.remove('active');
- this._active = false;
+ this._active = null;
}
};
return this._active;
@@ -219,23 +227,43 @@
* Show the menu.
* Currently this means that multiple menus may be loaded
* but not shown.
+ *
+ * @param {boolean} Boolean value to indicate if context
+ * is necessary (true) or if the main context should
+ * be shown if context fails.
+ *
*/
show : function (ifContext) {
+ var c = this._inputField.container();
+
// Menu is already active
- if (this.active()) {
+ if (this.active() !== null) {
+
+ // This does not work for alert currently!
+ if (this._active._type !== 'alert') {
+ c.removeChild(this._active.element());
+ };
+
+ // This may already be hidden!
+ this._active.hide();
+ this.active(null);
// Alert is not active
- if (!this._alert.unshow())
+ /*
+ if (!this._alert.unshow())
return;
+ */
};
// Get the menu
var menu;
if (menu = this.contextMenu(ifContext)) {
- var c = this._inputField.container();
- this.active(true);
- // c.classList.add('active');
+
+// TODO: Remove old element!
+
+ this.active(menu);
+
c.appendChild(menu.element());
menu.show();
menu.focus();
@@ -244,8 +272,16 @@
};
},
+ // Show an object in the containerField
+ // This will hide all other objects
+ // Accepts menus as well as alerts
+ show2 : function (obj) {},
+
+ // This will get the context of the field
+ getContext : function () {},
+
unshow : function () {
- this.active(false);
+ this.active(null);
this.inputField().element().focus();
}
};
diff --git a/dev/js/src/hint/alert.js b/dev/js/src/hint/alert.js
index a5b43de..f34fde8 100644
--- a/dev/js/src/hint/alert.js
+++ b/dev/js/src/hint/alert.js
@@ -8,6 +8,7 @@
return Object.create(this)._init(msg);
},
_init : function (msg) {
+ this._type = 'alert';
this.active = false;
this._element = document.createElement('div');
this._element.style.opacity = 0;
@@ -20,7 +21,7 @@
this._element.style.opacity = 1;
},
- unshow : function () {
+ hide : function () {
if (!this.active)
return false;
this._element.style.opacity = 0;
diff --git a/dev/js/src/hint/item.js b/dev/js/src/hint/item.js
index 3747a72..cfea816 100644
--- a/dev/js/src/hint/item.js
+++ b/dev/js/src/hint/item.js
@@ -22,8 +22,6 @@
this._name = params[0];
this._action = params[1];
this._lcField = ' ' + this._name.toLowerCase();
-
- console.log('!!!!');
if (params.length > 2) {
this._desc = params[2];
@@ -50,7 +48,7 @@
onclick : function (e) {
var m = this.menu();
var h = m.hint();
- m.hide();
+ // m.hide();
// Update input field
var input = h.inputField();
@@ -58,6 +56,7 @@
e.halt();
+ // show alt
h.show(true);
},
diff --git a/dev/js/src/match.js b/dev/js/src/match.js
index 07a46ec..28d2154 100644
--- a/dev/js/src/match.js
+++ b/dev/js/src/match.js
@@ -7,6 +7,7 @@
/*
* - Highlight (at least mark as bold) the match
* - Scroll to match vertically per default
+ * - A click on a table field and a tree node should at the field description to the fragments list.
*/
define([
'match/info',
diff --git a/dev/js/src/menu.js b/dev/js/src/menu.js
index 9f91e96..8619d89 100644
--- a/dev/js/src/menu.js
+++ b/dev/js/src/menu.js
@@ -11,6 +11,8 @@
* TODO: Add a "title" to a menu that is not scrollable.
* TODO: Make the menu responsive by showing less items on smaller screens
* or anytime items would be outside the screen.
+ * TODO: Add a .match() method to items for scrolling and probably for prefixing.
+ * TODO: Add static header (for title, sortation fields, but also for menu points like "fragments" and "history".
*/
define([
'menu/item',