[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    KEdit small improvement + [PATCH]
From:       Martin Paquette <gexcfxyy () umail ! corel ! com>
Date:       2001-04-02 15:43:12
[Download RAW message or body]

Hi,
  I've made a little improvement in KEdit: the save action is now
disabled until the document is really modified. Many users still use
KEdit (including me). If someone find this improvement useful, feel free
to add it to the cvs project (I don't have write access to cvs since
this is my first contribution :) ). Anyway, here is the diff:


Index: kedit.cpp
===================================================================
RCS file: /home/kde/kdeutils/kedit/kedit.cpp,v
retrieving revision 1.140
diff -c -r1.140 kedit.cpp
*** kedit.cpp   2001/03/26 05:34:20     1.140
--- kedit.cpp   2001/04/02 19:38:01
***************
*** 143,153 ****
--- 143,156 ----
          SLOT(setEnabled(bool)));
    connect(eframe, SIGNAL(copyAvailable(bool)),copyAction,
          SLOT(setEnabled(bool)));
+       connect(eframe, SIGNAL(textChanged()), this, 
+               SLOT(textChanged_slot()));
  
    undoAction->setEnabled(false);
    redoAction->setEnabled(false);
    cutAction->setEnabled(false);
    copyAction->setEnabled(false);
+   saveAction->setEnabled(false);
  
    setCentralWidget(eframe);
    eframe->setMinimumSize(200, 100);
***************
*** 166,172 ****
      eframe->setWordWrap(QMultiLineEdit::NoWrap);
    }
    eframe->setFont( mOptionState.font.font );
!   eframe->setModified(false);
  
    setSensitivity();
  
--- 169,175 ----
      eframe->setWordWrap(QMultiLineEdit::NoWrap);
    }
    eframe->setFont( mOptionState.font.font );
!   setModified_slot(false);
  
    setSensitivity();
  
***************
*** 203,209 ****
      KStdAction::open(this, SLOT(file_open()), actionCollection());
      recent = KStdAction::openRecent(this, SLOT(openRecent(const
KURL&)),
                                            actionCollection());
!     KStdAction::save(this, SLOT(file_save()), actionCollection());
      KStdAction::saveAs(this, SLOT(file_save_as()),
actionCollection());
      KStdAction::close(this, SLOT(file_close()), actionCollection());
      KStdAction::print(this, SLOT(print()), actionCollection());
--- 206,212 ----
      KStdAction::open(this, SLOT(file_open()), actionCollection());
      recent = KStdAction::openRecent(this, SLOT(openRecent(const
KURL&)),
                                            actionCollection());
!     saveAction = KStdAction::save(this, SLOT(file_save()),
actionCollection());
      KStdAction::saveAs(this, SLOT(file_save_as()),
actionCollection());
      KStdAction::close(this, SLOT(file_close()), actionCollection());
      KStdAction::print(this, SLOT(print()), actionCollection());
***************
*** 300,306 ****
        if(ok){
          openFile(fn, OPEN_READWRITE);
          location = filename;
!         eframe->setModified();
            eframe->setCursorPosition(line, col);
          setFileCaption();
            statusbar_slot();
--- 303,309 ----
        if(ok){
          openFile(fn, OPEN_READWRITE);
          location = filename;
!         setModified_slot();
            eframe->setCursorPosition(line, col);
          setFileCaption();
            statusbar_slot();
***************
*** 311,317 ****
        if(!filename.isEmpty()){
        openFile(filename, OPEN_READWRITE);
          location = filename;
!         eframe->setModified(false);
          eframe->setCursorPosition(line, col);
          setFileCaption();
          statusbar_slot();
--- 314,320 ----
        if(!filename.isEmpty()){
        openFile(filename, OPEN_READWRITE);
          location = filename;
!         setModified_slot(false);
          eframe->setCursorPosition(line, col);
          setFileCaption();
          statusbar_slot();
***************
*** 356,362 ****
  
    eframe->getCursorPosition(&line,&column);
    eframe->insertAt(string,line,column);
!   eframe->setModified(TRUE);
  
    statusbar_slot();
  }
--- 359,365 ----
  
    eframe->getCursorPosition(&line,&column);
    eframe->insertAt(string,line,column);
!   setModified_slot(TRUE);
  
    statusbar_slot();
  }
***************
*** 364,370 ****
  void TopLevel::paste(){
  
   eframe->paste();
!  eframe->setModified(TRUE);
  
   statusbar_slot();
  }
--- 367,373 ----
  void TopLevel::paste(){
  
   eframe->paste();
!  setModified_slot(TRUE);
  
   statusbar_slot();
  }
***************
*** 372,378 ****
  void TopLevel::cut(){
  
   eframe->cut();
!  eframe->setModified(TRUE);
   statusbar_slot();
  
  }
--- 375,381 ----
  void TopLevel::cut(){
  
   eframe->cut();
!  setModified_slot(TRUE);
   statusbar_slot();
  
  }
***************
*** 501,507 ****
        toplevel->location = url.path();
        toplevel->setFileCaption();
        recent->addURL( url );
!       toplevel->eframe->setModified(false);
        toplevel->setGeneralStatusField(i18n("Done"));
        toplevel->statusbar_slot();
        break;
--- 504,510 ----
        toplevel->location = url.path();
        toplevel->setFileCaption();
        recent->addURL( url );
!       toplevel->setModified_slot(false);      
        toplevel->setGeneralStatusField(i18n("Done"));
        toplevel->statusbar_slot();
        break;
***************
*** 538,544 ****
      if( result == KEDIT_OK )
      {
        recent->addURL( url );
!       eframe->setModified(true);
        setGeneralStatusField(i18n("Done"));
        statusbar_slot();
      }
--- 541,547 ----
      if( result == KEDIT_OK )
      {
        recent->addURL( url );
!       setModified_slot(true);
        setGeneralStatusField(i18n("Done"));
        statusbar_slot();
      }
***************
*** 645,651 ****
      }
    }
    eframe->clear();
!   eframe->setModified(false);
    location = QString::null;
    setFileCaption();
    statusbar_slot();
--- 648,654 ----
      }
    }
    eframe->clear();
!   setModified_slot(false);
    location = QString::null;
    setFileCaption();
    statusbar_slot();
***************
*** 939,944 ****
--- 942,956 ----
        eframe->doGotoLine();
  }
  
+ void TopLevel::textChanged_slot() {
+       saveAction->setEnabled(eframe->isModified());
+ }
+ 
+ void TopLevel::setModified_slot(bool bModified /*=true*/) {
+       eframe->setModified(bModified);
+       saveAction->setEnabled(bModified);
+ }
+ 
  void TopLevel::statusbar_slot(){
  
    QString linenumber;
***************
*** 1171,1177 ****
  
      KTempFile tmpFile;
      tmpFile.setAutoDelete(true);
!     eframe->setModified( true );
      saveFile( tmpFile.name(), false );
  
      if (KIO::NetAccess::upload( tmpFile.name(), _url ) == false)
--- 1183,1189 ----
  
      KTempFile tmpFile;
      tmpFile.setAutoDelete(true);
!     setModified_slot( true );
      saveFile( tmpFile.name(), false );
  
      if (KIO::NetAccess::upload( tmpFile.name(), _url ) == false)
***************
*** 1236,1242 ****
       eframe->clear();
    }
    eframe->insertText( &stream );
!   eframe->setModified(false);
    return KEDIT_OK;
  
  }
--- 1248,1254 ----
       eframe->clear();
    }
    eframe->insertText( &stream );
!   setModified_slot(false);  
    return KEDIT_OK;
  
  }
***************
*** 1390,1396 ****
       KMessageBox::sorry(this, i18n("Could not save file."));
       return KEDIT_RETRY;
    }
!   eframe->setModified(false);
    return KEDIT_OK;
  }
  
--- 1402,1408 ----
       KMessageBox::sorry(this, i18n("Could not save file."));
       return KEDIT_RETRY;
    }
!   setModified_slot(false);
    return KEDIT_OK;
  }
  
***************
*** 1424,1430 ****
          location = netFile;
          setFileCaption();
          recent->addURL(_url);
!         eframe->setModified(false);
          setGeneralStatusField(i18n("Done"));
      }
  }
--- 1436,1442 ----
          location = netFile;
          setFileCaption();
          recent->addURL(_url);
!         setModified_slot(false);
          setGeneralStatusField(i18n("Done"));
      }
  }
Index: kedit.h
===================================================================
RCS file: /home/kde/kdeutils/kedit/kedit.h,v
retrieving revision 1.57
diff -c -r1.57 kedit.h
*** kedit.h     2001/03/07 07:39:07     1.57
--- kedit.h     2001/04/02 19:38:01
***************
*** 151,156 ****
--- 151,157 ----
      KAction *copyAction;
      KAction *undoAction;
      KAction *redoAction;
+     KAction *saveAction;
  
      int open_mode;
      struct printinfo pi;
***************
*** 181,186 ****
--- 182,188 ----
      void gotoLine();
      void mail();
      void setGeneralStatusField(const QString &string);
+     void setModified_slot(bool bModified = true);
      void undo();
      void redo();
      void copy();
***************
*** 230,235 ****
--- 232,238 ----
        void setMiscOption( const SMiscState &misc );
        void editKeys();
        void editToolbars();
+       void textChanged_slot();      
  };
  
  #endif


--------------------
Thanks,
Martin Paquette
-- 
The address in the headers is not the poster's real email address.  Do not send
private mail to the poster using your mailer's "reply" feature.  CC's of mail 
to mailing lists are OK.  Problem reports to "postmaster@umail.corel.com".  
The poster's email address is "martinp@corel.com".

Boundless power to create. Anytime. Anywhere. Share Corel's vision.!
Visit http://www.corel.com/draw10.

 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic