geany/geany — pull request #138 by codebrainz (2013-05-10 05:45:09+00:00)
Title: Add Rename document feature

Accessible from MainMenu->Document->Rename, Documents sidebar tab context menu and tab label context menu. It opens a little dialog that lets you edit the file's basename. It's meant to be a simple and quick alternative to using the "Rename" button in the Save As dialog.

When the dialog is shown, the part of the basename in the entry before the last period/dot is selected. If one presses Enter on the entry it invokes the dialog's default response, and if the basename didn't change, the document is just saved with its old name (if needed). If the document is not saved on disk yet, a question dialog is presented notifying the user that an unsaved document cannot be renamed and offers them the option of saving the document.

#### Use case

I often want to rename files in the same directory quick, ex. changing "stuff.c" to "myns-stuff.c" or changing C++ headers from "foo.h" to "foo.hpp" or simple things like this and I find this way much quicker and less distracting from the task at hand (coding) than the alternatives (File->Save As->Choose Path->Press Rename Button or doing from shell/explorer and then close and re-opening the file).

#### Screenshots

![The rename document dialog](https://f.cloud.github.com/assets/181177/486672/7f0baee4-b930-11e2-9ad1-586c966d3573.png)

![The item in the main Document menu](https://f.cloud.github.com/assets/181177/486674/9afcfce8-b930-11e2-9404-b4677023c343.png)

![The item in the context menu of the sidebar's Documents tab](https://f.cloud.github.com/assets/181177/486677/ab0f24e4-b930-11e2-9370-72a0c0d85da0.png)

![The item in the context menu of the document's tab label](https://f.cloud.github.com/assets/181177/486678/b98d0626-b930-11e2-8b6d-02f2378016f4.png)

![The warning dialog for when the main Document menu's Rename item is activated and the file is not on disk](https://f.cloud.github.com/assets/181177/486680/c9435ba6-b930-11e2-9755-d17f1bc56ec8.png)

#### TODO/Notes/Future
* Should it have a keybinding? Which one by default?
* Which accelerator label underscore thing to use (if any) for the new menu item labels?
* It might be useful to show a path relative to the project base dir if a project is open in the rename dialog, for example if renaming a file from "src/blah.h" to "include/blah.h".
* It might also be useful to put "Clone" into the Documents sidebar tab and tab label context menus.
* Could get rid of the Save As warning dialog if someone has a decent way to make the Document->Rename menu item from Glade track whether the current document has a file on disk (is saved) and just change it's sensitivity so it couldn't be activated in that case.
* The word "Rename" is used in a general sense (change the document's name) and not in the other common use as meaning `mv` (rename the file, possibly moving it into a new directory, without copying), so it actually saves a copy and then removes the old file afterwards. The reason for this is that there's already all of the code to update the document state existing and it's easier (and probably even safer) to reuse the `document_save_file*()` functions rather than implement something with `g_rename()`, IMO.

If the addition is liked, it would be nice if someone could check the code (mostly in dialogs.c, rest is pretty trivial) and see if I missed some leaks, used utf8 vs locale on filenames correctly for display vs file system names, and also that the actual rename operation is sound from a technical/safety perspective. Much appreciated.