GNOME GUI Integration w.r.t IDEA GUI Launcher

13 / Feb / 2011 by Kushal Likhi 1 comments

One of the important part of any Installer is integrating and defining launchers for GUI. This post will demonstrate adding entries in menu bar and panel, using scripts in context of creating a GUI launcher for IDEA IDE.

currently IDEA does not come with any GUI Launcher but this does not mean that we cant have one. How cool it would be if we had an icon on the top panel to launch IDEA in Terminal mode.

IDEA LAUNCHER IN PANEL ->


Similarly an entry is also created in menu: application->programming->Idea
Download:
idea_desktop_Integration.tar.gz Check the installation guide below to see how to install

PROBLEM STATEMENT:
A program will be created to do IDEA GNOME GUI Integration, which launches IDEA in TERMINAL such that we can see whats happening in the background, that too with the ease of GUI one click quick launch. It requires following subtasks:

  1. Building Launch Environment for idea.sh: idea.sh is designed to launch in terminal with all PATH variables set for various SDK’s. if we try to launch it in a standalone terminal it will not work as environment is required. In this step we will generate the launch environment
  2. Adding Menu Bar Entry: in this we will add an entry to menu: application->programming->Idea using scripts, automated.
  3. Adding entry to panel: here we will add an entry for launcher in the quickLaunch panel on top of the screen.

Building Launch Environment
whenever terminal is launched it runs the .bashrc file which have the PATH variables to be set.
but we cant execute .bashrc in standalone terminals i.e terminals with no command point as GUI always launches applications in standalone terminals.
so the other option is:- extract all the PATH variables from .bashrc and create your own setup script for the terminal.
this can be achieved by simple commands:-
[shell]grep "export" ~/.bashrc |tee ~/.IDEALauncher[/shell]
this will extract all exported variables and make a file containing all of them in the home folder with the name .IDEALauncher
and we can execute this script to set the path via command:
[shell]chmod 777 ~/.IDEALauncher
. ~/.IDEALauncher[/shell]
Now it has set all the path variables needed for the launch.

the above mentioned task is stored in a file klaunch.sh and is the launcher start point. file is as follows:
Note: UI and echo’s have been removed here to make it more readable, in attached file lot other stuff is there.
[shell]
# IDEA Launcher Script for gnome desktop integration.
# By Kushal Likhi

#GET settings of enviornment variables and create a shell script for those
grep "export" ~/.bashrc |tee ~/.IDEALauncher

#set enviornment variables
chmod 777 ~/.IDEALauncher
. ~/.IDEALauncher

#launch IDEA
`idea.sh`
[/shell]

Setup Process
adding menu bar entries and panel entries is a part of setup process and is as follows:

“Everything in LINUX is a file”

yes, and using the above saying all we have to do is: create/edit/add some files
FOR Menu Entry we have to create a file: /usr/share/applications/idea.desktop and update cache to be safe
the Script is as follows for the setup file:
[shell]
#IDEA Desktop integration setup file
# (c) Kushal Likhi
#Ver 1.0

#clear screen for good clean looks
clear

#welcome message
echo "——————-WELCOME———————-"
echo ""
echo " SETUP Program for IDEA GNOME Integration"
echo " by: kushal likhi"
echo ""
echo "————————————————"

#read IDEA installation dir path
echo ""
read -p "Enter IDEA Bin Location, press enter to keep default(/opt/idea/bin/), note: end path with ‘/’:" ideahome

if [ -z "$ideahome"]
then
ideahome=/opt/idea/bin/
else
echo "path set!"
fi

echo ""
echo "Path set to: "$ideahome

#copy files
echo ""
echo "Generating launcher…."
sudo cp -fv klaunch.sh $ideahome
echo ""
echo "copying Icons…."
sudo cp -fv icon.png $ideahome
echo ""

#add menu entries
echo "checking for /usr/share/applications"

if [ -d "/usr/share/applications" ]
then
#found cache file
echo "found"
echo "Adding Entries…."

#NOTE: echo here is used to create files, NOT display on console, ‘>’ creates a file, and ‘>>’ appends to it.
sudo echo "[Desktop Entry]" > /usr/share/applications/idea.desktop
sudo echo "Type=Application" >> /usr/share/applications/idea.desktop
sudo echo "Encoding=UTF-8" >> /usr/share/applications/idea.desktop
#sudo echo "Version 1.0" >> /usr/share/applications/idea.desktop
sudo echo "Name=IDEA IDE" >> /usr/share/applications/idea.desktop
sudo echo "Comment=Launcher for IDEA by Kushal" >> /usr/share/applications/idea.desktop
sudo echo "Categories=Development;" >> /usr/share/applications/idea.desktop
sudo echo "Exec="$ideahome"klaunch.sh" >> /usr/share/applications/idea.desktop
sudo echo "Icon="$ideahome"icon.png" >> /usr/share/applications/idea.desktop
sudo echo "Terminal=true" >> /usr/share/applications/idea.desktop
echo ""
echo "updating /usr/share/applications/desktop.en_US.UTF8.cache"
sudo echo "[idea]" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Name=IDEA IDE" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Comment=Launcher for IDEA by Kushal" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Categories=Development;" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Exec="$ideahome"klaunch.sh" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Icon="$ideahome"icon.png" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Terminal=true" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "Type=Application" >> /usr/share/applications/desktop.en_US.UTF8.cache
sudo echo "" >> /usr/share/applications/desktop.en_US.UTF8.cache
echo ""
echo "adding pannel entry……"

#/usr/lib/gnome-panel/gnome-panel-add –launcher=/usr/share/applications/idea.desktop
chmod 777 panel

bash ./panel

echo ""
echo "Menu set….. Enjoy!!"
echo ""
echo "——> YOU WILL FIND ENTRY IN (Applications -> Programming) MENU"
echo ""
echo "NOTE: Run command ./panel to add panel entry explicitly. was unable to add panel in sudo mode"
else
# file not found
echo "ERROR! Does not exist! this setup works for GNOME only"
exit 1
fi
[/shell]
now here we have added menu entry.

Adding Panel Entry:
Ubuntu has made this task easy by providing us with a python script to manipulate panels.
so all we have to do is use that script.. 😀
so the code is as follows for the panel file:-
[shell]
echo "adding panel……"
/usr/lib/gnome-panel/gnome-panel-add –launcher=/usr/share/applications/idea.desktop –panel=top_panel_screen0
echo "panel entry added… "
[/shell]
you can also add to the bottom panel with the switch –panel=bottom_panel_screen0 , now the launch button will appear next to show desktop icon at the botton left corner.
we can also align them to left or right, all is documented in the script usage guide.

Installation Guide
installation is very simple, just follow the following steps:

  1. STEP 1: Download the files: idea_desktop_Integration.tar.gz
  2. STEP 2: Extract the files to a directory.
  3. STEP 3: go in the root of the extracted files and issue command
    [shell]
    sudo ./setup
    [/shell]
    then when asked enter idea path if it is different from the mentioned, if its same as mentioned just press enter.
  4. STEP 4: issue command:
    [shell]
    ./panel
    [/shell]
    this has to be issued seperate because the ubuntu script for panel does not work in sudo mode
  5. STEP 5: all set Enjoy!! now whenever you have to launch IDEA just click on the icon and it will launch gracefully

~~Kushal Likhi~~
http://www.intelligrape.com

FOUND THIS USEFUL? SHARE IT

comments (1 “GNOME GUI Integration w.r.t IDEA GUI Launcher”)

  1. Dan

    Really nice work, it’s exactly what I was looking for.

    Thanks for the effort of writing this, much appreciated.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *