Skip to content

Commit

Permalink
#25 select/deselect
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuque committed Feb 4, 2014
1 parent db2570c commit 94008c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
17 changes: 17 additions & 0 deletions inner/js/selection/selection-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,24 @@ if (!window.mobmap) { window.mobmap={}; }
this.fireAfterNewSession();
},

cancelSessionIfType: function(stype, fireAfter) {
if (this.currentSelectionSession) {
if (this.currentSelectionSession.getType() === stype) {
this.disposeCurrentSession();

if (fireAfter) {
this.fireAfterDisposeSession();
}
return true;
}
}

return false;
},

fireSessionDispose: function() { this.callResponders('selWillDisposeCurrentSession'); },
fireNewSession: function() { this.callResponders('selWillStartNewSession'); },
fireAfterDisposeSession: function() { this.callResponders('selDidDisposeSession'); },
fireAfterNewSession: function() { this.callResponders('selDidStartNewSession'); },

callResponders: function(methodName, arg1, arg2) {
Expand All @@ -73,6 +89,7 @@ if (!window.mobmap) { window.mobmap={}; }
// name | required
selWillDisposeCurrentSession : false,
selWillStartNewSession : false,
selDidDisposeSession : false,
selDidStartNewSession : false
};

Expand Down
21 changes: 16 additions & 5 deletions inner/js/ui/edit-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ if (!window.mobmap) { window.mobmap={}; }
onSelectionButtonClick: function(btnObj, e) {
switch(btnObj.name) {
case 'sel_clear': this.onSelectionClearButtonClick(); break;
case 'sel_rect':
if (!this.deselectSelectionRectButton()) {
this.onSelectionRectButtonDown();
}
break;
}
},

onSelectionButtonMousedown: function(btnObj, e) {
switch(btnObj.name) {
case 'sel_rect': this.onSelectionRectButtonDown(); break;
}
},

onSelectionClearButtonClick: function() {
Expand All @@ -108,6 +110,12 @@ if (!window.mobmap) { window.mobmap={}; }
}
},

deselectSelectionRectButton: function() {
var c = this.getOwnerSelectionController();
if (c) { return c.cancelSessionIfType(mobmap.SelectionSessionType.Rect, true); }
return false;
},

getOwnerSelectionController: function() {
if (!this.ownerApp) {return null;}
return this.ownerApp.getSelectionController() || null;
Expand All @@ -120,10 +128,14 @@ if (!window.mobmap) { window.mobmap={}; }
if (sess) {
currentType = sess.getType();
}

this.updateSelectionButtonsState(currentType);
},

selDidDisposeSession: function(selController) {
this.updateSelectionButtonsState(mobmap.SelectionSessionType.Unknown);
},

updateSelectionButtonsState: function(currentSessionType) {
var sel_name = null;
switch(currentSessionType) {
Expand All @@ -135,7 +147,6 @@ if (!window.mobmap) { window.mobmap={}; }
for (var i = 0;i < len;++i) {
var targetName = setButtonNames[i];
var btn = this.selectionButtonNameMap[targetName];
console.log(targetName , sel_name)
btn.setSelectedStyle(targetName === sel_name);
}
}
Expand Down

0 comments on commit 94008c4

Please sign in to comment.