Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: shiv12095 <[email protected]>
  • Loading branch information
shiv12095 committed Jun 19, 2017
1 parent 1d6a503 commit 5f8dc15
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ define(["../init/AppController"], function(controllers) {
$rootScope.$broadcast("closeEditor", $scope.index, true);
$uibModalInstance.dismiss("cancel");
};

$scope.cancel = function() {
$uibModalInstance.dismiss("cancel");
};

}
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ define(["../init/AppController"], function(controllers) {
controllers.controller("EditorController", EditorController);

EditorController.$inject = [
"$rootScope", "$scope", "$location", "$window", "$routeParams", "$compile",
"$q", "$rootScope", "$scope", "$location", "$window", "$routeParams", "$compile",
"$uibModal", "toastr", "ShareDataService", "ProjectDataService",
"EditorDataService", "PublishDataService", "ToastrService"
]

function EditorController($rootScope, $scope, $location, $window, $routeParams, $compile, $uibModal, toastr, ShareDataService, ProjectDataService, EditorDataService, PublishDataService, ToastrService) {
function EditorController($q, $rootScope, $scope, $location, $window, $routeParams, $compile, $uibModal, toastr, ShareDataService, ProjectDataService, EditorDataService, PublishDataService, ToastrService) {
$scope.error = null;
$scope.errorMessage = null;
$scope.validationError = false;
Expand Down Expand Up @@ -354,11 +354,12 @@ define(["../init/AppController"], function(controllers) {
});

$scope.$on("closeProject", function(event, save) {
if(save){
$scope.editors.forEach(function(editor){
editor.xtextServices.saveResource();
});
}
$scope.editors.forEach(function(editor){
if(!save){
editor.setValue(editor.lastSavedValue);
}
editor.xtextServices.saveResource();
});
$scope.closeProject();
});

Expand All @@ -370,13 +371,16 @@ define(["../init/AppController"], function(controllers) {
}

$scope.$on("closeEditor", function(event, index, save) {
var editor = $scope.editors[index];
if (save) {
var editor = $scope.editors[index];
editor.xtextServices.saveResource();
var tab = $scope.tabs[index];
var message = "Resource " + tab.filename + " saved";
var params = {message: message};
ToastrService.createSuccessToast(params);
}else{
editor.setValue(editor.lastSavedValue);
editor.xtextServices.saveResource();
}
$scope.closeEditor(index);
});
Expand Down Expand Up @@ -432,24 +436,12 @@ define(["../init/AppController"], function(controllers) {
}

$scope.openXtextEditor = function(tab) {
require(["webjars/ace/1.2.0/src/ace"], function() {
require(["xtext/xtext-ace"], function(xtext) {
var editor = xtext.createEditor({
xtextLang: tab.language,
syntaxDefinition: $scope.editorConfig[tab.language].syntaxDefinition,
serviceUrl: $scope.editorConfig[tab.language].serviceUrl,
enableFormattingAction: "true",
enableSaveAction: "true",
showErrorDialogs: "true",
parent: tab.editorDivId,
resourceId: tab.resourceId
});
$scope.editors.push(editor);
$scope.selectedEditor = $scope.editors[$scope.selectedTabIndex];
$scope.clearSearch();
$scope.isEditorOpen = true;
$scope.$apply();
});
$scope.createEditor(tab).then(function(editor){
$scope.editors.push(editor);
$scope.selectedEditor = $scope.editors[$scope.selectedTabIndex];
$scope.clearSearch();
$scope.isEditorOpen = true;
// $scope.$apply();
});
}

Expand Down Expand Up @@ -490,7 +482,8 @@ define(["../init/AppController"], function(controllers) {
var element = angular.element(document).find('#editors');
element.append('<div id="' + editorParentDivId + '" ng-show="selectedTabId==' + tabId + '"><div id="' + editorDivId + '" class="custom-xtext-editor"></div></div>');
$compile(element.contents())($scope);
$scope.addXtextEditor(editorDivId, model);
model.editorDivId = editorDivId;
$scope.addXtextEditor(model);
}
}).catch(function(error){
var message = resource.filename + " already exists";
Expand All @@ -500,31 +493,19 @@ define(["../init/AppController"], function(controllers) {
}

$scope.addXtextEditor = function(parentId, model) {
require(["webjars/ace/1.2.0/src/ace"], function() {
require(["xtext/xtext-ace"], function(xtext) {
editor = xtext.createEditor({
enableFormattingAction: "true",
enableSaveAction: "true",
showErrorDialogs: "true",
parent: parentId,
xtextLang: model.language,
resourceId: model.resourceId,
syntaxDefinition: $scope.editorConfig[model.language].syntaxDefinition,
serviceUrl: $scope.editorConfig[model.language].serviceUrl
});
$scope.editors.push(editor);
$scope.selectedEditor = $scope.editors[$scope.selectedTabIndex];
$scope.clearSearch();
var resourceId = $scope.selectedEditor.xtextServices.validationService._encodedResourceId;
var tab = $scope.tabs[$scope.selectedTabIndex];
tab["text"] = model.name;
tab["parent"] = $scope.rootParentId;
tab["status"] = $scope.valid;
$scope.addResource(tab);
$scope.selectTab($scope.selectedTabIndex);
$scope.isEditorOpen = true;
$scope.$apply();
});
$scope.createEditor(model).then(function(editor){
$scope.editors.push(editor);
$scope.selectedEditor = $scope.editors[$scope.selectedTabIndex];
$scope.clearSearch();
var resourceId = $scope.selectedEditor.xtextServices.validationService._encodedResourceId;
var tab = $scope.tabs[$scope.selectedTabIndex];
tab["text"] = model.name;
tab["parent"] = $scope.rootParentId;
tab["status"] = $scope.valid;
$scope.addResource(tab);
$scope.selectTab($scope.selectedTabIndex);
$scope.isEditorOpen = true;
// $scope.$apply();
});
}

Expand Down Expand Up @@ -782,5 +763,42 @@ define(["../init/AppController"], function(controllers) {
}
return unsavedFiles;
}

$scope.createEditor = function(model) {
var defer = $q.defer();
require(["webjars/ace/1.2.0/src/ace"], function() {
require(["xtext/xtext-ace"], function(xtext) {
var editor = xtext.createEditor({
enableFormattingAction: "true",
enableSaveAction: "true",
showErrorDialogs: "true",
parent: model.editorDivId,
xtextLang: model.language,
resourceId: model.resourceId,
syntaxDefinition: $scope.editorConfig[model.language].syntaxDefinition,
serviceUrl: $scope.editorConfig[model.language].serviceUrl
});
editor.commands.addCommand({
name: 'customSaveCommand',
bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
exec: function(editor) {
editor.xtextServices.saveResource();
editor.lastSavedValue = editor.getValue();
var tab = $scope.tabs[$scope.selectedTabIndex];
var message = "Resource " + tab.filename + " saved";
var params = {message: message};
ToastrService.createSuccessToast(params);
}
});
editor.xtextServices.loadResource().then(function(data){
editor.lastSavedValue = data.fullText;
defer.resolve(editor);
}, function(err){
defer.resolve(editor);
});
});
});
return defer.promise;
}
}
});

0 comments on commit 5f8dc15

Please sign in to comment.