Bug 60616

Summary: Cannot open file '%1' for writing, code templates will be lost when you close quanta
Product: [Unmaintained] quanta Reporter: Melvyn Sopacua <melvyn>
Component: generalAssignee: András Manţia <amantia>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: FreeBSD   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Melvyn Sopacua 2003-07-02 09:24:05 UTC
Version:           3.2-CVS-1 (using KDE 3.1.2)
Installed from:    compiled sources
Compiler:          gcc version 2.95.4 20020320 [FreeBSD]
OS:          FreeBSD (i386) release 4.8-STABLE

When adding an abbreviation, the above error message is generated. This *might* be due to the fact that I have 2 installations (one release and one CVS), since I also have 2 sets of each dtd.

It happens with the CVS version.
Comment 1 András Manţia 2003-07-02 17:14:17 UTC
Subject: Re:  New: Cannot open file '%1' for writing, code templates will be lost when you close quanta

I just remembered: this may be an access right problem. If the Quanta DTD 
files (quanta/tags) directory for the DTD you are trying to create 
abbreviations for is in a directory writable only for root (like usually the 
global KDEDIRS is), writing it as a user will fail. A solution is to start 
Quanta as root when you create the abbreviations. Please try it, and if it's 
working, let me know. In that case the fix might be easy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/AvbETQdfac6L/08RAsX7AJ4y5lvrJtDxFBy7kfZiqfuzLpKpHQCcDAZl
TtVa7XSSu4vqyGb26+tXXOQ=
=iEvU
-----END PGP SIGNATURE-----

Comment 2 András Manţia 2003-07-02 17:41:11 UTC
Subject: quanta

CVS commit by amantia: 

Change conflicting shortcut for Misc. Tag to Ctrl-Shift-T [#60616]. 
Clear the code field in the abbreviation settings on DTD change.

CCMAIL: 60616-done@bugs.kde.org


  M +1 -0      ChangeLog   1.185
  M +1 -0      quanta/dialogs/abbreviation.cpp   1.6
  M +1 -1      quanta/quantaview.cpp   1.27


--- quanta/ChangeLog  #1.184:1.185
@@ -18,4 +18,5 @@
     - opening project views or multiple files on startup is much faster
     - don't close quanta, if the user cancelled the toolbar saving [#59952]
+    - shortcut to Misc. Tag changed to Ctrl-Shift-T [#60616]
 
   - new features:

--- quanta/quanta/quantaview.cpp  #1.26:1.27
@@ -168,5 +168,5 @@ void QuantaView::initActions()
                         actionCollection, "tag_mail" );
 
-    (void) new KAction( i18n( "Misc. Tag..." ), "tag_misc", CTRL+Key_T,
+    (void) new KAction( i18n( "Misc. Tag..." ), "tag_misc", CTRL+SHIFT+Key_T,
                         this, SLOT( slotTagMisc() ),
                         actionCollection, "tag_misc" );

--- quanta/quanta/dialogs/abbreviation.cpp  #1.5:1.6
@@ -49,4 +49,5 @@ void Abbreviation::slotDTDChanged(const 
   saveTemplates();
   templatesList->clear();
+  codeEdit->clear();
   oldItem = 0L;
   QString dtdName = QuantaCommon::getDTDNameFromNickName(newDTDName);


Comment 3 András Manţia 2003-07-02 18:18:34 UTC
Sorry, closed by mistake. ;-)
Comment 4 Melvyn Sopacua 2003-07-03 22:34:47 UTC
Patch for saving works, but the same needs to be done for loading, because now on 
startup only $INSTALL_PREFIX/share/quanta/tags/$DTD_NAME/abbreviations is 
loaded. 
 
When you then save, the $KDEHOME/share/quanta/tags/$DTD_NAME/abbreviations 
file is overwritten. 
Comment 5 András Manţia 2003-07-04 09:36:48 UTC
Subject: quanta/quanta

CVS commit by amantia: 

Fix namespace editing in the attribute tree.
Load the abbreviations file from $KDEHOME if it's present there, even when multiple $KDEDIRS are defined. (part of bug 60616).

CCMAIL: 60616-done@bugs.kde.org


  M +1 -1      dialogs/abbreviation.cpp   1.11
  M +5 -2      document.cpp   1.176
  M +14 -3     quanta_init.cpp   1.301


--- quanta/quanta/document.cpp  #1.175:1.176
@@ -213,6 +213,9 @@ void Document::changeTagNamespace(Tag *t
     tag->namePos(nl, nc);
     reparseEnabled = false;
-    editIf->removeText(bl, bc+1, nl, nc-1);
+    editIf->removeText(bl, bc+1, nl, nc);
     reparseEnabled = true;
+  } else
+  {
+    tag->beginPos(bl, bc);
   }
   if (nameSpace.isEmpty())
@@ -222,5 +225,5 @@ void Document::changeTagNamespace(Tag *t
   {
     viewCursorIf->setCursorPositionReal((uint)bl, (uint)(bc+1));
-    insertText(nameSpace);
+    insertText(nameSpace+":");
   }
   quantaApp->slotNewLineColumn();

--- quanta/quanta/quanta_init.cpp  #1.300:1.301
@@ -1423,8 +1423,19 @@ void QuantaApp::readTagDir(QString &dirN
  //read the abbreviations files
   QString abbrevFile = dirName;
-  if (dirName.startsWith(qConfig.globalDataDir))
+  tmpStr = dirName;
+  QStringList resourceDirs = KGlobal::dirs()->resourceDirs("data");
+  bool dirFound = false;
+  for (uint i = 0; i < resourceDirs.count(); i++)
   {
-    abbrevFile = dirName.right(dirName.length() - qConfig.globalDataDir.length());
-    abbrevFile = KGlobal::dirs()->saveLocation("data", abbrevFile) +"/";
+    if (tmpStr.startsWith(resourceDirs[i]))
+    {
+      dirFound = true;
+      tmpStr = tmpStr.right(tmpStr.length() - resourceDirs[i].length());
+      break;
+    }
+  }
+  if (dirFound)
+  {
+    abbrevFile = KGlobal::dirs()->saveLocation("data", tmpStr) +"/";
   }
   abbrevFile.append("abbreviations");

--- quanta/quanta/dialogs/abbreviation.cpp  #1.10:1.11
@@ -188,5 +188,5 @@ void Abbreviation::saveTemplates()
 
     QFile f(s);
-    if (f.open(IO_WriteOnly))
+    if (f.open(IO_WriteOnly | IO_Truncate))
     {
       QTextStream str(&f);