Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using File Name in DSL
Using File Name in DSL [message #853830] Mon, 23 April 2012 11:20 Go to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Hi,

I defined my grammer in Xtext. I want to make my DSL more userfriendly now. When user create a new project and create a file(i.e: file1.mydsl ), I want to capture the file name and use it in file1.mydsl file.

For example, file1.mydsl can be like this:

//This is file1 you can define your model here.

I searched lots of example and read documentations but can not see any example.
I think I will do this by using validation package but how?

Thank you,
Re: Using File Name in DSL [message #853866 is a reply to message #853830] Mon, 23 April 2012 12:09 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Isn't it possible??

[Updated on: Mon, 23 April 2012 12:09]

Report message to a moderator

Re: Using File Name in DSL [message #853878 is a reply to message #853830] Mon, 23 April 2012 12:23 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
The easiest I can think of is to add a "new MyDSL-file" wizard since it
enables you to specify initial content (and the file name is known for
sure).

- henrik

On 2012-23-04 13:20, sbl Mising name wrote:
> Hi,
>
> I defined my grammer in Xtext. I want to make my DSL more userfriendly
> now. When user create a new project and create a file(i.e: file1.mydsl
> ), I want to capture the file name and use it in file1.mydsl file.
> For example, file1.mydsl can be like this:
>
> //This is file1 you can define your model here.
>
> I searched lots of example and read documentations but can not see any
> example.
> I think I will do this by using validation package but how?
>
> Thank you,
Re: Using File Name in DSL [message #853887 is a reply to message #853878] Mon, 23 April 2012 12:34 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Sorry but I couldn't understand what you mean exactly?

Thanks,
Re: Using File Name in DSL [message #853954 is a reply to message #853887] Mon, 23 April 2012 13:56 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
On 2012-23-04 14:34, sbl Mising name wrote:
> Sorry but I couldn't understand what you mean exactly?
>
> Thanks,

You can write an Eclipse "New File Wizard"-plugin for your file type.

Look at org.cloudsmith.geppetto.ui.wizard.NewModulefileWizard in project
cloudsmith/geppetto at github for an example.

(Although, the example does not use the capability to set the initial
content).

This solution is the easiest, because it is clear that the file is new.
Other possible customizations (inside the Xtext framework) would also be
possible, but there it would be difficult to determine the difference
between an empty file (empty on purpose) and one that is just created,
and you would probably not want empty files to become dirty with an
inserted comment as soon as they are opened.

Hope that helps.
Regards
- henrik
Re: Using File Name in DSL [message #854269 is a reply to message #853954] Mon, 23 April 2012 20:50 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Indeed, I want to add the file name at the beginning of empty mydsl file.
If I can solve it inside the Xtext framework, it will be better.

Thanks for your replies.
Re: Using File Name in DSL [message #854982 is a reply to message #854269] Tue, 24 April 2012 12:12 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Is there another way to solve this problem? Unfortunally, This solution is not working
Re: Using File Name in DSL [message #855147 is a reply to message #854982] Tue, 24 April 2012 15:01 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
On 2012-24-04 14:12, sbl Mising name wrote:
> Is there another way to solve this problem? Unfortunally, This solution
> is not working

Yes, there are other solutions, but they are kind of hacky - hence my
suggestion that when user creates a new empty file, you insert the text
then. At all (?) other locations it is somewhat complicated to know if
the empty file is a new empty file or a file that is emptied by the user.

You probably want the user to be able to save an empty file without the
comment mysteriously reappearing. Or if an empty file is checked into a
SCM that is not modified by the fact that it is opened in an editor.

Another solution is to validate an empty file and add a warning/comment
with a quick fix that helps the user.

You could probably also do something with hoover support - if the file
is empty a hoover appears that tells user what to do.

Regards
- henrik
Re: Using File Name in DSL [message #855887 is a reply to message #855147] Wed, 25 April 2012 07:24 Go to previous messageGo to next message
Michal S is currently offline Michal SFriend
Messages: 73
Registered: July 2011
Member
Hi,
Henrik's solution with File Wizard is really easy to do!
Just go to your .ui project -> plugin.xml -> Extensions -> Add -> Extension Wizard (tab) -> New File Wizard -> (customize here) -> Finish
Next step is even easier: go to wizard package of .ui project -> open the wizard class -> adjust openContentStream() method ...
Optionally, you can add to wizard to your shortcuts.
Michal
Re: Using File Name in DSL [message #856278 is a reply to message #855887] Wed, 25 April 2012 14:24 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Thanks for your replies.

With this solution I can specify a default name for my dsl but it is not what I exacty want.

My problem is, when I right click to my xtext project and Run As Eclipse Application a new Eclipse window is opening. Then, I create a general project and create a new file on that project. When I click to create a new file it asks me a name for my file. For example, I give my file name: test.mydsl

Then, an empty file is openning. I want to see //test.mydsl line top of my test.mydsl file


Thank you,
Re: Using File Name in DSL [message #856296 is a reply to message #856278] Wed, 25 April 2012 14:36 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
On 2012-25-04 16:24, sbl Mising name wrote:
> Thanks for your replies.
> With this solution I can specify a default name for my dsl but it is not
> what I exacty want.
>
no, that is a misunderstanding. The name is not fixed - why do you think
that?

> My problem is, when I right click to my xtext project and Run As Eclipse
> Application a new Eclipse window is opening. Then, I create a general
> project and create a new file on that project. When I click to create a
> new file it asks me a name for my file. For example, I give my file
> name: test.mydsl
>
> Then, an empty file is openning. I want to see //test.mydsl line top of
> my test.mydsl file
>

Exactly, but you also write a "new .mydsl" wizard which does the same as
the "new file" only inserts your text. When you run your project, this
plugin is also part of your configuration and you can use that in your
self hosted environment.

It is really quite simple.

- henrik
Re: Using File Name in DSL [message #857242 is a reply to message #856296] Thu, 26 April 2012 11:30 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
Thanks very much,

I think I must have more experience in here. My last question: Where can I write default informations in that file? I can not see any field while costomizing my wizard.
Re: Using File Name in DSL [message #857272 is a reply to message #857242] Thu, 26 April 2012 12:09 Go to previous messageGo to next message
sbl Missing name is currently offline sbl Missing nameFriend
Messages: 32
Registered: March 2011
Member
OK! It is OK right now, thank you very much for your helpss ! Smile
Re: Using File Name in DSL [message #857323 is a reply to message #857272] Thu, 26 April 2012 13:00 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2500
Registered: July 2009
Senior Member
On 2012-26-04 14:09, sbl Mising name wrote:
> OK! It is OK right now, thank you very much for your helpss ! :)
Glad you figured it out.

- henrik
Previous Topic:General purpose language possible
Next Topic:Conditional expression with xtext
Goto Forum:
  


Current Time: Sat Nov 22 03:22:32 GMT 2014

Powered by FUDForum. Page generated in 0.03524 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software