<commit_before>/**
 * BMotion Studio for ProB Standalone Module
 *
 */
define(['angularAMD', 'bms.func', 'angular', 'prob.graph', 'prob.iframe', 'prob.editor', 'prob.ui', 'prob.common'], function (angularAMD, bms) {

    var module = angular.module('prob.standalone', ['prob.graph', 'prob.iframe', 'prob.editor', 'prob.ui', 'prob.common'])
        .run(['ws', 'editableOptions', 'bmsMainService', function (ws, editableOptions, bmsMainService) {
            bmsMainService.mode = 'ModeStandalone';
            editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
            /*
             // Load native UI library
             var gui = require('nw.gui');
             // Get the current window
             var win = gui.Window.get();
             // Listen to close event
             win.on('close', function () {
             this.hide(); // Pretend to be closed already
             ws.emit('clientClosed', {data: {}});
             //this.close(true);
             });
             */
        }])
        .factory('fileDialogService', ['$q', function ($q) {
            return {
                open: function () {
                    var defer = $q.defer();
                    var fileDialog = $("#fileDialog");
                    fileDialog.click(function () {
                        this.value = null;
                    });
                    fileDialog.change(function () {
                        var template = $(this).val();
                        defer.resolve(template);
                    });
                    fileDialog.trigger('click');
                    return defer.promise;
                }
            };
        }])
        .controller('bmsVisualizationCtrl', ['$scope', 'fileDialogService', 'bmsModalService', '$http', function ($scope, fileDialogService, bmsModalService, $http) {

            $scope.setVisualization = function (vis) {
                sessionStorage.template = vis.template;
                $scope.visualization = vis;
            };

            $scope.openFileDialog = function () {
                fileDialogService.open().then(function (template) {
                    var filename = template.replace(/^.*[\\\/]/, '');
                    if (filename === 'bmotion.json') {
                        $http.get(template).success(function (data) {
                            $scope.setVisualization({
                                id: bms.uuid(),
                                name: data.name,
                                template: template
                            });
                        });
                    } else {
                        bmsModalService.setError('Invalid file, please open a bmotion.json file!');
                    }
                });
            };

            if (sessionStorage.template) {
                $scope.setVisualization({
                    template: sessionStorage.template,
                    id: bms.uuid()
                });
            }

        }])
        .directive('bmsDropZone', ['$http', 'bmsModalService', function ($http, bmsModalService) {
            return {
                link: function ($scope, element) {

                    // prevent default behavior from changing page on dropped file
                    window.ondragover = function (e) {
                        e.preventDefault();
                        return false
                    };
                    window.ondrop = function (e) {<commit_msg>added window menu to standalone mode<commit_after>/**
 * BMotion Studio for ProB Standalone Module
 *
 */
define(['angularAMD', 'bms.func', 'angular', 'prob.graph', 'prob.iframe', 'prob.editor', 'prob.ui', 'prob.common'], function (angularAMD, bms) {

    var module = angular.module('prob.standalone', ['prob.graph', 'prob.iframe', 'prob.editor', 'prob.ui', 'prob.common'])
        .run(['editableOptions', 'bmsMainService', 'GUI', 'Window', 'fileDialogService', '$rootScope', function (editableOptions, bmsMainService, GUI, Window, fileDialogService, $rootScope) {

            bmsMainService.mode = 'ModeStandalone';
            editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'

            var openDialog = function (type) {
                $rootScope.$broadcast('openDialog_' + type);
            };

            // Create node-webkit menu
            var windowMenu = new GUI.Menu({
                type: "menubar"
            });

            // File menu
            var fileMenu = new GUI.Menu();
            windowMenu.append(new GUI.MenuItem({
                label: 'File',
                submenu: fileMenu
            }));
            fileMenu.append(new GUI.MenuItem({
                label: 'Open Visualization',
                click: function () {
                    fileDialogService.open().then(function (template) {
                        $rootScope.$broadcast('setVisualization', template);
                    });
                }
            }));

            // ProB menu
            var probView = new GUI.Menu();
            windowMenu.append(new GUI.MenuItem({
                label: 'ProB',
                submenu: probView
            }));
            probView.append(new GUI.MenuItem({
                label: 'Events',
                click: function () {
                    openDialog('Events');
                }
            }));
            probView.append(new GUI.MenuItem({
                label: 'History',
                click: function () {
                    openDialog('CurrentTrace');
                }
            }));
            probView.append(new GUI.MenuItem({
                label: 'State',
                click: function () {
                    openDialog('StateInspector');
                }
            }));
            probView.append(new GUI.MenuItem({
                label: 'Animations',
                click: function () {
                    openDialog('CurrentAnimations');
                }
            }));
            probView.append(new GUI.MenuItem({
                label: 'Console',
                click: function () {
                    openDialog('GroovyConsoleSession');
                }
            }));
            probView.append(new GUI.MenuItem({
                label: 'Model Checking',
                click: function () {
                    openDialog('ModelCheckingUI');
                }
            }));

            // Diagram menu
            var diagramMenu = new GUI.Menu();
            windowMenu.append(new GUI.MenuItem({
                label: 'Diagram',
                submenu: diagramMenu
            }));
            diagramMenu.append(new GUI.MenuItem({
                label: 'Element Projection Diagram',
                click: function () {
                    $rootScope.$broadcast('openElementProjectionModal');
                }
            }));
            diagramMenu.append(new GUI.MenuItem({
                label: 'Trace Diagram',
                click: function () {
                    $rootScope.$broadcast('openTraceDiagramModal');
                }
            }));

            Window.menu = windowMenu;

        }])
        .factory('GUI', function () {
            return require('nw.gui');
        })
        .factory('Window', ['GUI', function (gui) {
            return gui.Window.get();
        }])
        .factory('fileDialogService', ['$q', function ($q) {
            return {
                open: function () {
                    var defer = $q.defer();
                    var fileDialog = $("#fileDialog");
                    fileDialog.click(function () {
                        this.value = null;
                    });
                    fileDialog.change(function () {
                        var template = $(this).val();
                        defer.resolve(template);
                    });
                    fileDialog.trigger('click');
                    return defer.promise;
                }
            };
        }])
        .controller('bmsVisualizationCtrl', ['$scope', 'fileDialogService', 'bmsModalService', '$http', function ($scope, fileDialogService, bmsModalService, $http) {

            $scope.setVisualization = function (template) {

                var filename = template.replace(/^.*[\\\/]/, '');
                if (filename === 'bmotion.json') {
                    $http.get(template).success(function () {
                        sessionStorage.template = template;
                        $scope.visualization = {
                            id: bms.uuid(),
                            template: template
                        };
                    });
                } else {
                    bmsModalService.setError('Invalid file, please open a bmotion.json file!');
                }

            };

            $scope.openFileDialog = function () {
                fileDialogService.open().then(function (template) {
                    $scope.setVisualization(template);
                });
            };

            $scope.$on('setVisualization', function (evt, template) {
                $scope.setVisualization(template);
            });

            if (sessionStorage.template) {
                $scope.setVisualization(sessionStorage.template);
            }

        }])
        .directive('bmsDropZone', ['$http', 'bmsModalService', function ($http, bmsModalService) {
            return {
                link: function ($scope, element) {

                    // prevent default behavior from changing page on dropped file
                    window.ondragover = function (e) {
                        e.preventDefault();
                        return false
                    };
                    window.ondrop = function (e) {
{'fraction_non_alphanumeric': 0.12433374333743337, 'fraction_numerical': 0.0006150061500615006, 'mean_word_length': 1.260658016682113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6930137', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2219, 'n_words': 467}