RSS Feed
Jan 23

Shortcut of the month: CTRL + SHIFT + T (Aptana)

Posted on Sunday, January 23, 2011 in Shortcut

A few days ago I was working with eclipse (or more precisely with Aptana 1.5) on a project. I have accidentally closed a file, although I was not finished yet. In trying to open this file again I could have go to the “Project View” open it through the directory list.

The Shortcut

We know this shortcut from many other programs to open a recently closed window/tab. So why shouldn’t it work in eclipse? So I just tried to reopen the file useing the shortcut:

CTRL + SHIFT + T

Unfortunately, this shortcut does not open the last closed file, but it has opened a window titled “Open PHP Element”, which looks like this:

Open PHP Element

This is a search window where you can search for classes, functions and constants. By default it always searches in all projects. As you can see in my example search, you can also search for methods of a class. But it is important to know, that the search always start at the beginning of an identifier. However, preceding the search term with an asterisk you can search within the identifier for a search term:

Open PHP Element with an asterix in the search term

Das ist auch dann notwendig, wenn man z.B. den Methodennamen einer Klasse kennt, nicht aber den Namen der Klasse, in der die Methode enthalten ist.

It is also necessary if you only know the method name of a class, but not the name of the class, in which the method is included.

Double-clicking on an entry of the search result opens the file in which the class, function or constant is defined, and jumps to the appropriate location. This is especially useful if the corresponding functions are not described with the help of PHPDoc and you want to find out exactly what the function does. Especially when working with WordPress, it is often very helpful to look up whether there is a filter in a function, when this filter is running and what it does.

In my current installation of Eclipse with the Aptana plugin, the shortcut can only be used if I’ve just opened a file that is associated with one of the Aptana editors. So if I just work in a text file or an SQL file, which is associated with a native eclipse editor, the shortcut does not work.

The indexing of the files for this search runs in the background. It is mostly performed after an update from a SVN respository. I was often wondered about what exactly Aptana does after an update for such a long time, but now I know.

Related shortcuts und alternative plugins

There is also a function called “Open Ressource”. With this shortcut you can open a file by it’s name (and you can also use an asterix in the search term):

CTRL + SHIFT + R

But to search for files, I use the plugin GotoFile which can even handle small typos within the search term. You can either access the plugin directly (blank) or you can mark a word before opening the plugin, which makes finding files even faster (e.g. you are searching for a file that in included with the include() orrequire() function). The shortcut to open the plugin is the following:

CTRL + ALT + N

The plugin hasn’t been maintained since 2006, but it also works with the latest version of eclipse (3.6.1) and without problems. It can’t be added through the “Software Updates …”. Instead you can simply unzip the zip archive into the plugins folder of your Eclipse installation.

Conclusion

I’m very excited from the newly discovered function. Because many times I know exactly how a function is called, but not necessarily where it was implemented. But even if you know where it is implemented, you can jump so much quicker to the appropriate place. It has saved me quite a lot of time searching.

I hope that the shortcut (or the plugin) may also help you in your daily work. If any of you has a great suggestion for a shortcut I would be very happy about a comment. I will post it on my blog ot you can write the post and I publish it for you.

Jan 1

Happy new year and a small shortcut

Posted on Saturday, January 1, 2011 in Common, Shortcut

I wish all my regular readers (and those who want to be) a happy new year 2011. Fortunately, the Jugendmedienschutz-Staatsvertrag has not been adopted, so that I can still safely tell you about interesting topics related to web development.

One of my regular readers is my colleague Michael, who has pointed me on a new shortcut in the office and asked me if it would be worthy of a “shortcut of the month”. He is very handy, but I’m sorry Michael, there are 2 alternatives to it, so he will not make it to a shortcut of the month. But I want to introduce him anyway:

ALT + ESC

With this shortcut you can cycle through the open programs in Windows without seeing the previews of the corresponding program. Strictly speaking, the currently active window moves to the end of the z-order, so it can’t simple be switched back to the previous program by using the shourtcut again.

Because it changes so the usual behavior when switching between programs and since Windows Vista introduced the great “Flip 3D” function, the shortcut is probably used only by very few (if they know him at all). A detailed overview of the program switch shortcuts can be found on the Alt-Tab page in the English Wikipedia.

Now I wish once again a happy new year and enjoy reading my other blog articles!

Dec 9

Shortcut of the monats: ALT + SHIFT (Windows)

Posted on Thursday, December 9, 2010 in Shortcut

For many of you this shortcut will not be new, but I didn’t know him for a long time and many friends who have been using Windows for decades haven’t knew him until recently. I also found him by chance.

The shortcut

The shortcut is at least available in Windows XP and later. Whether it existed also in earlier versions I cannot say at present, because I do not have Windows running in a previous version in a VM or a computer anymore. But now let’s introduce the shortcut and what he is good for:

ALT + SHIFT

With this shortcut you can change the input language in Windows. Those of you, using the “Input Language bar” should see a change in the input language by using the key combination.

But why this shortcut is so important? In a German Windows version mostly German and English are set as input languages and German is set as the default. Many German users accidentally pressed that key combination, without knowing it. Then only in the program you used the combination, the input language switched to English. Since Windows can adjust the input language for each program, the confusion is complete when you switch to another program and the input language is German again.

Conclusion and tip

With this shortcut you can change the language at any time immediately, if you accidentally changed it. As many of you rarely or never use the English keyboard layout (since all the letters can be typed with the German keyboard layout), I’d give you the following advice: The best thing to do is removing the English input language via the control panel. That will protect you from accidentally switching the input language.

Nov 18

Shortcut of the month: CTRL + ALT + J (eclipse)

Posted on Thursday, November 18, 2010 in Shortcut

I don’t actually know if there will always be a shortcut of the month or even one a week, but recently I found a new shortcut, which I would like to share with you. Even after finding it, I couldn’t find any documentation about it in the internet.

The shortcut

But now let’s introduce the shortcut. I work a lot with eclipse (especially with the plugin Aptana). That’s where I accidently found the new shortcut:

CTRL + ALT + J

But what does the shortcut actually do? With the shortcut you can convert multiple lines into a single line statement of code. It deletes line breaks and tabs (or multiple whitespaces) at the beginning of the line. All previous lines will be separated with a single whitespace in only one line.

An example

Let’s take a look on an example you’ll probably have regularly. We take a tiny CSS file as input (my current footer styles):

/* footer styles */
#footer {
    margin: 0;
    padding: 0 0 0 20px;
    list-style: none;
    color: white
}

#footer li {
    margin: 0;
    padding: 10px 0;
    font: 11px Arial, Helvetica, sans-serif;
}

#footer li.left {
    float: left;
    width: 35%;
}

#footer li.right {
    float: right;
    width: 65%;
}

Quite often you would like to write styles more compact. Therefore you usually have to manually delete all the line breaks and tabs (or use some complex search and replace rules with regular expressions). But with the shortcut it all goes very easy. You just have to make e.g. the lines 1 to 6 and use the shortcut CTRL+ALT+J on the selection. You repeat this with all the following definitions in the brackets. Afterwards you can delete the line breaks between the definitions and you will get the following result:

/* footer styles */
#footer { margin: 0; padding: 0 0 0 20px; list-style: none; color: white }
#footer li { margin: 0; padding: 10px 0; font: 11px Arial, Helvetica, sans-serif; }
#footer li.left { float: left; width: 35%; }
#footer li.right { float: right; width: 65%; }

Another Example

The shortcut can be used for other types of languages and not only for CSS. Good examples are switch-case blocks or XML structures. You can use the shortcut to format the source code more readable:

Switch-case before:

switch($var){
	case 1 :
		func1();
		break;
	case 2 :
		func2();
		break;
	case 3 :
		func3();
		break;
	default :
		func();
}

Switch-case after:

switch($var){
	case 1 : func1(); break;
	case 2 : func2(); break;
	case 3 : func3(); break;
	default : func();
}

As you can see, you can use the shortcut on many constructs to make them simpler and more readable. A nice application is minifying CSS code. Therefore you simple mark all the CSS code in the file and use the shortcut. In languages with single line comment, you can’t use it to minify the code as everything after the first comment would be commented out.

Boundaries of the shortcuts and conclusion

The shortcut cannot be used, when line breaks are necessary. It can also lead to problems with HTML as it might add additional whitespaces in the text. But for constructs where whitespaces have no effect on the execution, it can make the code more readable. It is some kind of reverse shortcut to the CTRL+SHIFT+F shortcut which will format the source code nicely. I really like this new shortcut and I hope it can also help you to save some time.

Oct 29

Change page title in the Thematic theme with the thematic_doctitle filter

Posted on Friday, October 29, 2010 in WordPress

For a blog I use the Thematic Theme. It provides the basis for own so-called Child Themes and can be customized in many ways. In addition to the normal WordPress actions and filters Thematic provides its own Theme Action Hooks and Theme Filter.

Some of them are very well documented and there are examples on the net. But now I append a text to the page title (i.e. the text inside the <title> tags in <head>) of every single page of the blog. Although the function thematic_doctitle() is discussed on the page of the Theme Filters in detail in an example, I could not imagine that it has to be written so complicated and with so many lines of source code. Therefore, I again check the source code to find the lines where the function is defined.

The thematic_doctitle filter

The source code of the filter can be found in the files “wp-content/themes/thematic/library/extensions/header-extensions.php” at line 26 (in Thematic version 0.9.6.2). The interesting part looks like this:

	// Filters should return an array
	$elements = apply_filters('thematic_doctitle', $elements);

	// But if they don't, it won't try to implode
	if(is_array($elements)) {
		$doctitle = implode(' ', $elements);
	}
	else {
		$doctitle = $elements;
	}

	$doctitle = "\t" . "<title>" . $doctitle . "</title>" . "\n\n";

	echo $doctitle;

As I could find out, the return of a separate filter function may be either a string or an array. If it is an array, each element will be connected to a string using the implode() function. I have also analyzed the contents of the arrays. Depending on the page there is only one element in the array, or even more parts that are separated by a “Separator” element.

Extending the title with a function

Basically, it was irrelevant how the array looks like to my purposes, I just wanted to add something behind the original title. So I wrote a simple function that extends the title using the filter:

function my_doctitle($doctitle) {
	return array_merge($doctitle, array('suffix' => '| example.com'));
}
add_filter('thematic_doctitle','my_doctitle');

This tiny function add an array with the key “suffix” to the $doctitle array. Using the array_merge() it will merged to the original array and then returned directly.

Conclusion

So instead of copying almost the complete thematic_doctitle filter to attach only a small string afterward, it has paid off, to look at the source code. This enabled us to achieve the desired result in just four lines.

Since I use so many filters and action hooks in my functions.php file, it’s even more important to see whether it couldn’t be done a lot easier. Otherwise, at the end, I would have copied the half (or even more) of the filters source code used in the Thematic Theme into my functions.php, without really having to.

I hope that I could show you once again, the you should not be afraid to study the source code of a product you want to use or extend from time to time. Not only in this case has it saved me a lot of work.

Oct 8

Customize the WP-Instant Plugin for your theme

Posted on Friday, October 8, 2010 in WordPress

All of you have already tried or at least heard of the great new feature of Google, the “Instant Search”. Since this really is a great feature, I decided to program such a plugin for the WordPress community. But despite the enormous extensibility of WordPress this wasn’t an easy task. Unfortunately, for a layman, who previously had no contact with themes, it is probably difficult to get the plugin to work, as he has to go a little deeper into the source code at least twice.

First of all, the original “search loop” must be copied into a file named wp-instant-search-template.php. This file must then be copied into your theme directory. The “search loop” can usually be found in a file called search.php in your theme directory. It might for example look like this (from the old “default” theme):

<?php
/**
 * @package WordPress
 * @subpackage Default_Theme
 */

get_header(); ?>

	<div id="content" class="narrowcolumn" role="main">

	<?php if (have_posts()) : ?>

		<h2 class="pagetitle">Search Results</h2>

		<div class="navigation">
			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
		</div>

		<?php while (have_posts()) : the_post(); ?>

			<div <?php post_class() ?>>
				<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
				<small><?php the_time('l, F jS, Y') ?></small>

				<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
			</div>

		<?php endwhile; ?>

		<div class="navigation">
			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
		</div>

	<?php else : ?>

		<h2 class="center">No posts found. Try a different search?</h2>
		<?php get_search_form(); ?>

	<?php endif; ?>

	</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

You’ll need the part within the DIV with the ID “content”. In general the “search loop” starts with if(have_posts()) and ends with endif;. So from the example you have to copy lines 11-41 into the “wp-instant-search-template.php” file.

If this step is done, the Instant Search should already create the correct output. However, now this content still has to be inserted in the right DIV. We can find the ID of this DIV quite easily from the example source code. It is, of course, the value “content” asin the previous step we have just copied the contents of this DIV. This ID is then entered in the setup page of the plugin:

Screenshot of the settings page

This should have been the last step of the customization. If it still does not work or if you have any other issues, just leave a comment on this or on the original plugin post. If you have any suggestions for enhancements on the plugin I would also like to hear them.

Oct 8

WP-Instant Plugin

Posted on Friday, October 8, 2010 in WordPress

Integrates a Google Instant Search to your blog. The wp-instant plugin uses the Ajax.Updater function of script.aculo.us and the Form.Element.DelayedObserver class. A jQuery implementation will be following soon.

A more detailed instruction on how to customize the plugin can be found here: Customize the WP-Instant plugin for your theme

Installation:

Installation trough WordPress admin pages:

  1. Go to the admin page Plugins -> Add New
  2. Search for wp-instant and choose the plugin
  3. Choose the action install
  4. Click on Install now
  5. Activate the plugin after install has finished (with the link or trough the plugin page)
  6. You might have to edit the settings, especially the “Content tag ID” value
  7. Create a wp-instant-search-template.php file including the part of the “search loop” within the “Content ID tag”

Installation using WordPress admin pages:

  1. Download the plugin zip file: wp-instant.1.1.zip
  2. Go to the admin page Plugins -> Add New
  3. Choose the Upload link under the Install Plugins headline
  4. Browse for the zip file and click Install Now
  5. Activate the plugin after install has finished (with the link or trough the plugin page)
  6. You might have to edit the settings, especially the “Content tag ID” value
  7. Create a wp-instant-search-template.php file including the part of the “search loop” within the “Content ID tag”

Installation using ftp:

  1. Download the plugin zip file: wp-instant.1.1.zip
  2. Unzip und upload the files to your /wp-content/plugins/ directory
  3. Activate the plugin through the Plugins menu in WordPress
  4. You might have to edit the settings, especially the “Content tag ID” value
  5. Create a wp-instant-search-template.php file including the part of the “search loop” within the “Content ID tag”

Change Log:

  • 1.1 Fixing bug with uninitialized variables
  • 1.0 Use AJAX the way it’s described here: http://codex.wordpress.org/AJAX_in_Plugins
  • 0.2 Using STYLESHEETPATH as primary folder to search for search result template
  • 0.1 First stable release

If you like the plugin or if something is missing I would like to here it. Just leave a comment on this page or on my WordPress plugin page.

PayPal - The safer, easier way to pay online! PayPal - The safer, easier way to pay online!

Jul 25

Kau-Boy’s Opensearch Plugin

Posted on Sunday, July 25, 2010 in WordPress

Integrate a browser search arrording to the Opensearch spezification.

Your visitors can do a search on your post very quickly and on any time. You don’t need to setup any information. Just install and activate the plugin!

Installation:

Installation trough WordPress admin pages:

  1. Go to the admin page Plugins -> Add New
  2. Search for kau-boy and choose the plugin
  3. Choose the action install
  4. Click on Install now
  5. Activate the plugin after install has finished (with the link or trough the plugin page)

Installation using WordPress admin pages:

  1. Download the plugin zip file: kau-boys-opensearch.0.1.zip
  2. Go to the admin page Plugins -> Add New
  3. Choose the Upload link under the Install Plugins headline
  4. Browse for the zip file and click Install Now
  5. Activate the plugin after install has finished (with the link or trough the plugin page)

Installation using ftp:

  1. Download the plugin zip file: kau-boys-opensearch.0.1.zip
  2. Unzip und upload the files to your /wp-content/plugins/ directory
  3. Activate the plugin through the Plugins menu in WordPress

Screenshots:

Screenshot of the autodiscovery in Firefox

Screenshot in Firefox

Change Log:

  • 0.1 First stable release

If you like the plugin or if something is missing I would like to here it. Just leave a comment on this page or on my WordPress plugin page.

PayPal - The safer, easier way to pay online! PayPal - The safer, easier way to pay online!

Jun 12

WordPress 3 is right around the corner

Posted on Saturday, June 12, 2010 in WordPress

A third release candidate for WordPress was just announced. On the developer blog post for RC3 of WordPress you can even find a small Haiku:

Last call; final bugs
Itch, scratch, contort; calmly wait
For now: RC3

There is also a request to plugin developers. They are asked to test their plugins with the new release candidate. I already checked my 3 current plugins and I couldn’t find any errors.

As there are only 9 open and active tickets left, I hope that we can use WordPress 3 very soon on our blogs. I am least looking forward to it.

May 10

All plugins works with WordPress 3.0

Posted on Monday, May 10, 2010 in WordPress

Today I tested the current beta (3.0-beta2-14526) of the upcoming WordPress version. The good news for all users of some of my plugins is, that I could successfully tested all my plugins with the current beta.

As I stick to some standards while implementing my plugins and I didn’t use any DEPRECATED functions, I am pretty sure that all of the plugins will still work with the final version of WordPress 3.0 but I will check the compatibility with the latest NIGHTLY BUILD from time to time. If I find any issues with these builds, I try to solve them before the final version of WP 3.0 will be released.

If any of you has already found some issues with my plugins in combination with WP 3.0 or if you have issues with your current version of WordPress, please leave a comment on the plugins pages or on this post.

I wish all of us a lot of fun with the new upcoming features of WP 3.0 and I hope that we can enjoy the final version soon.

Impressum