Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Oh how I love Ubuntu and all its features, but this "bug" has been making me angry for so long and I've finally decided to ask for help here.

I've assigned all .php files to be opened with gedit whenever I double-click them in nautilus. Now, the behavior is strange.

  1. I have no gedit running
  2. I double click a file to be opened
  3. A gedit window opens and the file loads
  4. I double click another file to be opened

Now, there are 2 possible outcomes:

5A) The file opens in the same gedit window in a new tab

5B) The file opens in a new gedit window, resulting in 2 gedits running.

Whether A or B happens seems to be totally random and keeps on going infinitely. That means I double click on 100 files and I might end up with 60 gedits, some of which will have 1 tab, some will have 2 tabs, some will have 3 tabs...

This is extremely annoying and a fix for this would be very appreciated. Anyone ever tried to fix this problem?

This has happened in Ubuntu 10.04, 10.10 and 11.10. All Ubuntu versions I've ever tested.

share|improve this question

3 Answers 3

up vote 19 down vote accepted
+200

Why...

gedit has quite an interesting algorithm to determine whether it opens a new instance or if it opens in a tab in an existing instance.

Located in the source file gedit-app.c in the function static boolean is_in_viewport, the algorithm tests if the current gedit instance is

  1. in the same screen number and display name
  2. in the same workspace
  3. greater than 25% of the edges of the view port

If all are true then gedit opens in the same instance in a new tab otherwise it opens in a new window.

In summary - the only realistic way of changing the behaviour is to change the algorithm...

How...

The following is a quick way to get a consistent way of opening gedit... it will always open a new instance.

install the basic development tools

sudo apt-get install devscripts build-essential fakeroot 

get the source

cd ~/Downloads
mkdir build
cd build
apt-get source gedit
cd gedit-3.2*

make the change

Open gedit-app.c

gedit gedit/gedit-app.c

enter image description here

add return FALSE; as shown and save.

What this does is to always exit the routine saying "i'm not running in a viewport and therefore always open a new instance"

If you use return TRUE; this will always open in an existing instance of gedit in a new tab...

give it a unique package name

OK, we need to give the package a unique name to prevent repository updates from overwriting your changed package

gedit debian/changelog

now append +yourname to the top line version and save the file i.e.

Note - to be absolutely sure - after installing the modified package below, lock the version as per the linked question below.

enter image description here

build the package

sudo apt-get build-dep gedit
debuild -i -us -uc -b

Go for a coffee...

cd ..
sudo dpkg -i gedit*.deb

Linked Question:

  1. How to prevent updating of a specific package?
share|improve this answer
1  
This, my sir, is SICK! Thanks a lot, hope this will work ... –  Richard Rodriguez Nov 14 '11 at 22:55
    
... certainly did during my testing ... N.B. - I used the other answers observation that if you drag gedit to overlap the edges, a new instance is opened, but if you have gedit within the desktop, the new instance is opened in a tab. With the above compilation - it always opens in a new instance or tab depending upon with compiled with "return FALSE" or "return TRUE". –  fossfreedom Nov 14 '11 at 23:00
    
I'm officially confirming this solution WORKING! –  Richard Rodriguez Nov 15 '11 at 0:08
3  
holy sh*t @fossfreedom, I bow to you sir, you have done this time, the quality and solution of this answer is imba. If I could I would spend the all day pressing that vote up button! Gj. –  Bruno Pereira Nov 15 '11 at 11:34
    
exceptional answear! I see it to be usefull to other packages too, thx vm! btw, on ubuntu 12.10 debuild -us -uc failed, and I solved with this command dpkg-buildpackage -b tip from this thread askubuntu.com/questions/226495/… –  Aquarius Power May 10 '13 at 7:39

I wanted to have all files opened in only one gedit window. I didn't find this information somewhere else, but with the following changes I managed to have all text files open in only one window as new tabs, no mather how I open them (via launcher, via nautilus, via Gnome DO).

  1. Get the display number: type echo $DISPLAY in the command line. e.g. you get :0 as your display number.

  2. Open /usr/share/applications/gedit.desktop as superuser with a text editor.

  3. Change the line saying:

    Exec=gedit %U
    

    to

    Exec=gedit --display=:0 %U
    

    where :0 is your display number.

share|improve this answer
    
Much better than recompiling gedit and doing weird package hacks. Thanks! –  rcrogers May 14 at 23:07

This doesnt happen randomly

By default Gedit isnt made to open many instances but one one each display. If u open in display where isnt yet Gedit will open files in Gedit witch exists now in that display from witch is opened file.

So u can make 1st instance of gedit to be on All workspaces so it follows ur active display. Or work on each workspace with each project and each with its own opened Gedit`s. In keyboard shortcuts u can make new shortcut for toggling window beeing on all workspaces.

OR its possible to make it allways open in new instance using shortcut command in Open With.. gedit --new-window

So u can try in php properties open with reset and put new opening with just Gedit

using gedit --help-all ull see other option of opening with gedit.

And u can also try removing gedit with all configuration files and installing it clean using sudo apt-get purge gedit && sudo apt-get clean && sudo apt-get update && sudo apt-get install gedit

UPDATE: I was able to reproduce- when moving window a little off screen then opening some file opens in new window. It somehow thinks that its in another Display.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.