PHP
  Home arrow PHP arrow Page 5 - Building Your Own Desktop Notepad Application Using PHP-GTK
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building Your Own Desktop Notepad Application Using PHP-GTK
By: K.K.Sou
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2008-09-23


    Table of Contents:
  • Building Your Own Desktop Notepad Application Using PHP-GTK
  • Assumptions
  • Calling each respective function
  • Edit Operations
  • About the modified flag

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building Your Own Desktop Notepad Application Using PHP-GTK - About the modified flag
    ( Page 5 of 5 )

    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:

    $this->buffer->set_modified(false);

    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) {

    $this->set_title(true);

    }


    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';

    $this->glade->get_widget('window1')->set_title($title);

    }

    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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT