Home arrow PHP arrow Page 5 - Building Your Own Desktop Notepad Application Using PHP-GTK

About the modified flag - PHP

If you think building a desktop application such as Notepad is difficult, think again. If you use PHP-GTK, it's almost ridiculously easy. This article will show you how. By the time you're done, you'll have a full cross-platform application in about 100 lines.

  1. Building Your Own Desktop Notepad Application Using PHP-GTK
  2. Assumptions
  3. Calling each respective function
  4. Edit Operations
  5. About the modified flag
By: K.K.Sou
Rating: starstarstarstarstar / 9
September 23, 2008

print this article



The modified flag works as follows. First you need to register for the  'modified-changed' signal on the text buffer.

$this->buffer->connect('modified-changed', array(&$this, 'on_modified_changed'));

When you start a new document or right after saving a document, you reset the modified flag with:


Then any time the text buffer is changed, the on_modified_changed() callback function will be called. In this example, all we did is update the title to add '(*)' behind the filename.

public function on_modified_changed($buffer) {



function set_title($modified = false) {

$filename = $this->filename;

if ($filename=='') $filename = 'Untitled';

if ($modified) $title = $filename.' (*) - php-gtk2 Notepad';

else $title = $filename.' - php-gtk2 Notepad';



The complete sample code and glade file

Click on the following links to download the complete sample code and the corresponding glade file.

Download link: Notepad App Source

Final Words

We've come to the end of this article. In this tutorial, you have seen how to build your own desktop notepad application using PHP-GTK, in just 100+ lines of code!

Of course, there are some functionalities that have not been implemented yet, such as Undo, Redo, Replace and File Print.

There is also room for improvement in some of the functionalities. For example, when no text is selected, the menu items Cut, Copy and Delete should be grayed out. When the user has modified an opened document, and then selects File New or File Open, the program should have a prompt that says "The text in the xxx.txt file has changed. Do you want to save the changes?"

You might want to try implementing these as an exercise. If there are enough requests, I will post a sample solution as a follow-up to this article.

Lastly, in case you are not too familiar with some of the Gtk widgets such as GtkMenuItems and GtkDialog, you might want to refer to the site kksou.com which contains sample codes with explanations for each individual widget. If you are new to PHP-GTK, you might also want to read the free online ebook "PHP-GTK2 Demysitified."

>>> More PHP Articles          >>> More By K.K.Sou

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: