Skip to content

Commit

Permalink
added selection support for concrete syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mthiede committed Jun 13, 2010
1 parent adf14fd commit 2cf11dd
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 2 deletions.
1 change: 1 addition & 0 deletions concrete/ui/concrete_ui.js
Expand Up @@ -10,6 +10,7 @@ Concrete.UI = {
'proceed_dialog',
'open_element_dialog',
'search_replace_dialog',
'preferences_dialog',
'layout_manager',
'toolbar',
'module_browser',
Expand Down
Binary file added concrete/ui/images/preferences-system.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions concrete/ui/preferences_dialog.js
@@ -0,0 +1,74 @@
Concrete.UI.PreferencesDialog = Class.create(Concrete.UI.AbstractDialog, {

initialize: function($super, options) {
options = options || {};
var dialogElement = this._createDomElement();
$super(dialogElement, options);
this.syntaxInput = dialogElement.down(".syntax_input");
},

_createDomElement: function() {
if ($('ct_preferences_dialog')) return $('ct_preferences_dialog');
Element.insert($$('body').first(), { bottom:
"<div id='ct_preferences_dialog' class='popup_dialog' style='display: none; position: fixed; z-index: 1000'>" +
"<div class='shadow'></div>" +
"<div class='dialog_box'>" +
"<div class='title_bar'>Preferences" +
"<a class='close_button'></a>" +
"</div>" +
"<div class='container'>" +
"<p class='label'>Concrete Syntax</p>" +
"<select class='dropdown_input syntax_input'>" +
"</select>" +
"<div style='text-align: center; margin: 10px'>" +
"<input class='button_input proceed_button' type='button' value='OK' />" +
"<input class='button_input cancel_button' type='button' value='Cancel' />" +
"</div>" +
"</div>" +
"</div>" +
"</div>" });
return $('ct_preferences_dialog');
},

_proceed: function() {
new Ajax.Request("/setConcreteSyntax", {
method: 'get',
parameters: {"ident": this.syntaxInput.value},
onSuccess: function(transport) {
},
onFailure: function() {
}
});
},

_buttonPressed: function(element) {
if (element == this.dialogElement.down(".cancel_button")) {
this.close();
}
},

open: function($super, options) {
$super();
new Ajax.Request("/concreteSyntaxes", {
method: 'get',
onSuccess: function(transport) {
if (transport.responseText.isJSON()) {
var synDesc = transport.responseText.evalJSON();
Element.replace(this.syntaxInput,
"<select class='dropdown_input syntax_input'>" +
synDesc.syntaxes.collect(function(s) {
var selected = (s.ident == synDesc.selected) ? "selected" : "";
return "<option "+selected+" value=\""+s.ident+"\">"+s.name+"</option>";
}).join("") +
"</select>"
);
this.syntaxInput = this.dialogElement.down(".syntax_input");
}
}.bind(this),
});
}

});



13 changes: 13 additions & 0 deletions concrete/ui/style.css
Expand Up @@ -43,6 +43,11 @@ a.ct_toolbar_icon:hover {
background-image: url(images/emblem-symbolic-link.png);
}

.ct_preferences_button {
float:right;
background-image: url(images/preferences-system.png);
}

.ct_stop_server_button {
float:right;
background-image: url(images/process-stop.png);
Expand Down Expand Up @@ -198,6 +203,14 @@ a.ct_toolbar_icon:hover {
color: black;
}

.popup_dialog .dropdown_input {
width: 100%;
margin-top: 5px;
margin-bottom: 5px;
border: 1px solid grey;
color: black;
}

.popup_dialog .button_input {
padding: 5px 20px 5px 20px;
border: 1px solid grey;
Expand Down
6 changes: 6 additions & 0 deletions concrete/ui/workbench.js
Expand Up @@ -42,6 +42,8 @@ Concrete.UI.Workbench = {
metamodelProvider: mp
});

var preferencesDialog = new Concrete.UI.PreferencesDialog();

// Event Handler

Event.observe(window, 'click', function(event) {
Expand Down Expand Up @@ -101,6 +103,10 @@ Concrete.UI.Workbench = {
new Ajax.Request("/exit");
});

toolbar.addCommand({buttonClass: "ct_preferences_button"}, function() {
preferencesDialog.open();
});

function jumpReference(module, ident) {
var href = "#"+module+((ident && ":"+ident) || "");
var lastm = window.location.href.match(/#.*/);
Expand Down
57 changes: 57 additions & 0 deletions lib/concrete/concrete_syntax_provider.rb
@@ -0,0 +1,57 @@
module Concrete

class ConcreteSyntaxProvider

class ConcreteSyntax
attr_accessor :ident, :dir, :name, :desc, :htmlTemplates, :cssStyleFile
end

def initialize(configDirs, logger)
@configDirs = configDirs
@logger = logger
@selectedSyntax = nil
end

def selectedSyntax
@selectedSyntax || syntaxes.first
end

def selectSyntax(ident)
@selectedSyntax = syntaxes.find{|s| s.ident == ident}
end

def syntaxesAsJson
'{ "syntaxes": [' + syntaxes.collect do |s|
'{ "ident": "'+s.ident+'", "name": "'+s.name+'" }'
end.join(", ") + '], "selected": "'+@selectedSyntax.andand.ident.to_s+'" }'
end

def syntaxes
result = []
@configDirs.each do |cd|
Dir.entries(cd).sort.each do |sd|
next if sd == "." || sd == ".."
syntaxDir = cd+"/"+sd
templatesFile = syntaxDir + "/templates.html"
styleFile = syntaxDir + "/style.css"
unless File.exist?(templatesFile) || File.exist?(styleFile)
@logger.warn("Concrete syntax dir without a templates.html or a style.css: #{syntaxDir}")
next
end
s = ConcreteSyntax.new
s.ident = syntaxDir.gsub("\\","/")
s.dir = syntaxDir
s.name = sd
s.desc = ""
s.cssStyleFile = styleFile if File.exist?(styleFile)
s.htmlTemplates = File.read(templatesFile) if File.exist?(templatesFile)
result << s
end
end
result
end

end

end

16 changes: 14 additions & 2 deletions lib/concrete/server.rb
Expand Up @@ -4,9 +4,10 @@ module Concrete

class Server

def initialize(workingSet, dataProvider, htmlRoot, options={})
def initialize(workingSet, dataProvider, syntaxProvider, htmlRoot, options={})
@workingSet = workingSet
@dataProvider = dataProvider
@syntaxProvider = syntaxProvider
@htmlRoot = htmlRoot
@mutex = Mutex.new
@server = WEBrick::HTTPServer.new(:Port => (options[:port] || 1234))
Expand All @@ -25,10 +26,17 @@ def start

def handleRequest(req, res)
if req.path == "/"
res.body = File.read(@htmlRoot+"/editor.html")
editorHtml = File.read(@htmlRoot+"/editor.html")
editorHtml.sub!(/<!--\s+html templates\s+-->/, @syntaxProvider.selectedSyntax.htmlTemplates) if @syntaxProvider.selectedSyntax
res.body = editorHtml
elsif req.path =~ /^\/html\/(.*)/
File.open(@htmlRoot+"/"+$1, "rb") do |f|
res.body = f.read
end
elsif req.path =~ /^\/syntax\/(.*)/ && @syntaxProvider.selectedSyntax
File.open(@syntaxProvider.selectedSyntax.dir+"/"+$1, "rb") do |f|
res.body = f.read
puts res.body.size
end
elsif req.path =~ /^\/concrete\/(.*)/
File.open(File.dirname(__FILE__)+"/../../"+$1, "rb") do |f|
Expand All @@ -49,6 +57,10 @@ def handleRequest(req, res)
body = req.body[identDelim+1..-1]
@dataProvider.setJsonModel(ident, body)
end
elsif req.path == "/concreteSyntaxes"
res.body = @syntaxProvider.syntaxesAsJson
elsif req.path == "/setConcreteSyntax"
@syntaxProvider.selectSyntax(req.query["ident"])
elsif req.path =~ /\bmetamodel\.js/
@mutex.synchronize do
res.body = @dataProvider.metamodelAsJson
Expand Down

0 comments on commit 2cf11dd

Please sign in to comment.