Author Topic: "Save all" button  (Read 9417 times)

Offline raph

  • Almost regular
  • **
  • Posts: 242
"Save all" button
« on: June 09, 2007, 03:29:21 pm »
Hi guys,

when working with c::b I noticed, that I missed a "Save all" feature, which saves files, projects and the workspace at once, so I made a little patch.
A new item is added to the file menu:


Since I never used the print button in the main toolbar, I decided to replace it with a "save all" button:


I'm not really good at graphics, but I created two icons for this (out of the existing ones) and attached them to this post (filenames contain hints, where they should be put into).

Here is the patch:
Code
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp (revision 4079)
+++ src/sdk/editormanager.cpp (working copy)
@@ -913,7 +913,7 @@
     for (int i = 0; i < m_pNotebook->GetPageCount(); ++i)
     {
         EditorBase* ed = InternalGetEditorBase(i);
-        if (ed && !ed->Save())
+        if (ed && ed->GetModified() && !ed->Save())
         {
             wxString msg;
             msg.Printf(_("File %s could not be saved..."), ed->GetFilename().c_str());
Index: src/sdk/projectmanager.cpp
===================================================================
--- src/sdk/projectmanager.cpp (revision 4079)
+++ src/sdk/projectmanager.cpp (working copy)
@@ -1015,7 +1015,8 @@
     for (int i = 0; i < prjCount; ++i)
     {
         cbProject* project = m_pProjects->Item(i);
-        if (SaveProject(project))
+        bool isModified = project->GetModified();
+        if (isModified && SaveProject(project))
             ++count;
     }
     UnfreezeTree(true);
Index: src/src/main.cpp
===================================================================
--- src/src/main.cpp (revision 4079)
+++ src/src/main.cpp (working copy)
@@ -127,6 +127,7 @@
 int idFileOpenDefWorkspace = XRCID("idFileOpenDefWorkspace");
 int idFileSaveWorkspace = XRCID("idFileSaveWorkspace");
 int idFileSaveWorkspaceAs = XRCID("idFileSaveWorkspaceAs");
+int idFileSaveAll = XRCID("idFileSaveAll");
 int idFileCloseWorkspace = XRCID("idFileCloseWorkspace");
 int idFileClose = XRCID("idFileClose");
 int idFileCloseAll = XRCID("idFileCloseAll");
@@ -264,6 +265,7 @@
     EVT_UPDATE_UI(idFileSaveProjectAs, MainFrame::OnProjectMenuUpdateUI)
     EVT_UPDATE_UI(idFileSaveProjectAllProjects, MainFrame::OnProjectMenuUpdateUI)
     EVT_UPDATE_UI(idFileSaveProjectTemplate, MainFrame::OnProjectMenuUpdateUI)
+    EVT_UPDATE_UI(idFileSaveAll, MainFrame::OnProjectMenuUpdateUI)
     EVT_UPDATE_UI(idFileCloseProject, MainFrame::OnProjectMenuUpdateUI)
     EVT_UPDATE_UI(idFileCloseAllProjects, MainFrame::OnProjectMenuUpdateUI)
 
@@ -339,6 +341,7 @@
     EVT_MENU(idFileOpenDefWorkspace,  MainFrame::OnFileOpenDefWorkspace)
     EVT_MENU(idFileSaveWorkspace,  MainFrame::OnFileSaveWorkspace)
     EVT_MENU(idFileSaveWorkspaceAs,  MainFrame::OnFileSaveWorkspaceAs)
+    EVT_MENU(idFileSaveAll,  MainFrame::OnFileSaveAll)
     EVT_MENU(idFileCloseWorkspace,  MainFrame::OnFileCloseWorkspace)
     EVT_MENU(idFileClose,  MainFrame::OnFileClose)
     EVT_MENU(idFileCloseAll,  MainFrame::OnFileCloseAll)
@@ -2337,6 +2340,20 @@
     DoUpdateAppTitle();
 }
 
+void MainFrame::OnFileSaveAll(wxCommandEvent& event)
+{
+    Manager::Get()->GetEditorManager()->SaveAll();
+    Manager::Get()->GetProjectManager()->SaveAllProjects();
+
+    if (Manager::Get()->GetProjectManager()->GetWorkspace()->GetModified()
+        && Manager::Get()->GetProjectManager()->SaveWorkspace())
+    {
+        AddToRecentProjectsHistory(Manager::Get()->GetProjectManager()->GetWorkspace()->GetFilename());
+    }
+    DoUpdateStatusBar();
+    DoUpdateAppTitle();
+}
+
 void MainFrame::OnFileSaveProjectTemplate(wxCommandEvent& event)
 {
     TemplateManager::Get()->SaveUserTemplate(Manager::Get()->GetProjectManager()->GetActiveProject());
Index: src/src/main.h
===================================================================
--- src/src/main.h (revision 4079)
+++ src/src/main.h (working copy)
@@ -81,6 +81,7 @@
         void OnFileOpenDefWorkspace(wxCommandEvent& event);
         void OnFileSaveWorkspace(wxCommandEvent& event);
         void OnFileSaveWorkspaceAs(wxCommandEvent& event);
+        void OnFileSaveAll(wxCommandEvent& event);
         void OnFileCloseWorkspace(wxCommandEvent& event);
         void OnFileClose(wxCommandEvent& event);
         void OnFileCloseAll(wxCommandEvent& event);
Index: src/src/resources/main_menu.xrc
===================================================================
--- src/src/resources/main_menu.xrc (revision 4079)
+++ src/src/resources/main_menu.xrc (working copy)
@@ -101,8 +101,7 @@
         <help>Save the active file under a different name</help>
       </object>
       <object class="wxMenuItem" name="idFileSaveAllFiles">
-        <label>Save a&amp;ll files</label>
-        <accel>Ctrl-Shift-S</accel>
+        <label>Save all files</label>
         <help>Save all modified files</help>
       </object>
       <object class="separator"/>
@@ -136,6 +135,13 @@
         <help>Close current workspace</help>
       </object>
       <object class="separator"/>
+      <object class="wxMenuItem" name="idFileSaveAll">
+        <label>Save a&amp;ll</label>
+        <bitmap>images\16x16\filesaveall.png</bitmap>
+        <accel>Ctrl-Shift-S</accel>
+        <help>Save all files, projects and the workspace</help>
+      </object>
+      <object class="separator"/>
       <object class="wxMenuItem" name="idFileClose">
         <label>&amp;Close file</label>
         <bitmap>images\16x16\fileclose.png</bitmap>
Index: src/src/resources/main_toolbar.xrc
===================================================================
--- src/src/resources/main_toolbar.xrc (revision 4079)
+++ src/src/resources/main_toolbar.xrc (working copy)
@@ -19,10 +19,10 @@
   <longhelp>Save current file</longhelp>
   <bitmap>images/filesave.png</bitmap>
  </object>
- <object class="tool" name="idFilePrint">
-  <tooltip>Print</tooltip>
-  <longhelp>Print current file or all files</longhelp>
-  <bitmap>images/fileprint.png</bitmap>
+ <object class="tool" name="idFileSaveAll">
+  <tooltip>Save all</tooltip>
+  <longhelp>Save all files, projects and the workspace</longhelp>
+  <bitmap>images/filesaveall.png</bitmap>
  </object>
  <object class="separator"/>
   <object class="tool" name="idEditUndo">
Index: src/src/resources/main_toolbar_16x16.xrc
===================================================================
--- src/src/resources/main_toolbar_16x16.xrc (revision 4079)
+++ src/src/resources/main_toolbar_16x16.xrc (working copy)
@@ -18,10 +18,10 @@
   <longhelp>Save current file</longhelp>
   <bitmap>images/16x16/filesave.png</bitmap>
  </object>
- <object class="tool" name="idFilePrint">
-  <tooltip>Print</tooltip>
-  <longhelp>Print current file or all files</longhelp>
-  <bitmap>images/16x16/fileprint.png</bitmap>
+ <object class="tool" name="idFileSaveAll">
+  <tooltip>Save all</tooltip>
+  <longhelp>Save all files, projects and the workspace</longhelp>
+  <bitmap>images/16x16/filesaveall.png</bitmap>
  </object>
  <object class="separator"/>
   <object class="tool" name="idEditUndo">
You also find it on berlios.

Regards
raph

[attachment deleted by admin]

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: "Save all" button
« Reply #1 on: July 04, 2007, 08:21:03 am »
this got into svn in rev 4212, but it's buggy  :P
the project file doesn't get saved in some circumstances

procedure how to produce the bug:
1* open an existing project
2* remove any file from the project
3* press the "Save All" button
4* close CB (no annoying reminder to save anything)
5* open the project again
6* enjoy the previously removed files in your project again  :shock:

brgds, tiwag

update:
it seems, that removing a file from the project doesn't mark the project modified
you can close CB or close workspace without any warning about a modified project
« Last Edit: July 04, 2007, 08:26:56 am by tiwag »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: "Save all" button
« Reply #2 on: July 04, 2007, 10:15:06 am »
this got into svn in rev 4212, but it's buggy  :P
the project file doesn't get saved in some circumstances

procedure how to produce the bug:
1* open an existing project
2* remove any file from the project
3* press the "Save All" button
4* close CB (no annoying reminder to save anything)
5* open the project again
6* enjoy the previously removed files in your project again  :shock:

brgds, tiwag

update:
it seems, that removing a file from the project doesn't mark the project modified
you can close CB or close workspace without any warning about a modified project

I could not reproduce it the way you described, but following your instructions wrong the first time (:P) I stumbled upon the bug. It is now fixed.
Be patient!
This bug will be fixed soon...

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: "Save all" button
« Reply #3 on: July 04, 2007, 10:34:16 am »
... I could not reproduce it the way you described, but following your instructions wrong the first time (:P) I stumbled upon the bug.
  :P

thanks for the fix !

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: "Save all" button
« Reply #4 on: July 04, 2007, 08:12:17 pm »
Hmm... to be honest, I'm unhappy such a feature is being built-in now.

Could that not have gone into a plugin that adds this button? Then people who think they need it, could load that plugin.

To me, it is really not only a useless feature, but something that actually hinders workflow. There's a function that I will 100% certain never want to use, and it's placed in the middle between "save" and "undo", which are the two most often used buttons.

If you accidentially save a file (overwriting the one on disk) you can always hit "undo". But there is no undo for saving a project or a workspace. So now, when you temporarily add a compiler option to a project to make a build, you have to pay attention to no accidentially hit some stupid button, or you can do a svn revert right away too...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline raph

  • Almost regular
  • **
  • Posts: 242
Re: "Save all" button
« Reply #5 on: July 04, 2007, 08:30:43 pm »
I disagree thomas, but I do understand your point of view.
I think putting such "core" functionality into plugins is bad practice and will sooner or later flood codeblocks, make it confusing and hard to learn and in the end will slow it down.
Would adding a annoyingdialog solve the problem?

On the long term we have to think about making menus and toolbars fully customizable in order to reach maximum flexibility.
See e.g.
Quote from: wxAUI roadmap
Customizable toolbars for adding/removing icons and changing icon size preferences

Offline PsYhLo

  • Almost regular
  • **
  • Posts: 157
Re: "Save all" button
« Reply #6 on: July 04, 2007, 08:59:57 pm »
i think it would be better if there is a button/check box from where to choose the button on/off
by default will be on

sorry for my bad english :)

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: "Save all" button
« Reply #7 on: July 04, 2007, 10:52:15 pm »
Is a nice feature in my opinion!

Offline gnewt

  • Single posting newcomer
  • *
  • Posts: 4
Re: "Save all" button
« Reply #8 on: July 05, 2007, 04:25:10 am »
So wouldn't it be better if you could undo saving projects and workspaces? The addition of 'save all'  in conjunction with some form of "undo save for projects and workspaces" would IMO cater for the broadest range of users. I don't think it would need to be multi-level, just revert to previously saved version.

Hmm... to be honest, I'm unhappy such a feature is being built-in now.
[...]
If you accidentially save a file (overwriting the one on disk) you can always hit "undo". But there is no undo for saving a project or a workspace. So now, when you temporarily add a compiler option to a project to make a build, you have to pay attention to no accidentially hit some stupid button, or you can do a svn revert right away too...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: "Save all" button
« Reply #9 on: July 05, 2007, 07:48:59 am »
I think this should be configurable. I'm too scrupulous with my projects. I think it's better if we leave this option by default and add a "Did you know?" tip to enable it.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: "Save all" button
« Reply #10 on: July 05, 2007, 11:15:27 am »
Would adding a annoyingdialog solve the problem?
No, that would make it worse. I regret ever creating that class.

I think putting such "core" functionality into plugins is bad practice and will sooner or later flood codeblocks, make it confusing and hard to learn and in the end will slow it down.
That's what Firefox is like, though. There are hundreds of plugins that add a button here or a menu item there. It seems to work ok.
The argument about slowing down may be correct with the present plugin API, if you load 60 or 70 plugins, but that's an implementation detail.
Quote
Customizable toolbars for adding/removing icons
Something like that will be needed some day, agreed. Yiannis worked on such a thing long, long ago (January/February 2006?).

So wouldn't it be better if you could undo saving projects and workspaces?
It might be better, or it might not, unsure. I'm not aware of any program having such a behaviour, it would be unintuitive at best, a pain to implement and possibly unstable at worst.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."