Emerald Editor Discussion
April 23, 2017, 09:03:02 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: "Close Other" option  (Read 11937 times)
0 Members and 1 Guest are viewing this topic.
zara
Prospector
*
Posts: 5


« on: May 05, 2008, 11:33:31 am »

I don't know if anyone has worked on this specific option, but anyhow, here are the patches to make so as to get a menu option for closing all documents save for the active one:

Index: /trunk/res/resource.h
===================================================================
--- /trunk/res/resource.h   (revision 238)
+++ /trunk/res/resource.h   (working copy)
@@ -582,6 +582,7 @@
 #define ID_FILE_CLOSE_ALL               40007
 #define ID_FILE_RELOAD_AS               40008
 #define ID_SYNTAX_RELOAD                40009
+#define ID_FILE_CLOSE_OTHERS            40010
 #define ID_EDIT_DELETE                  41000
 #define ID_EDIT_CUT_APPEND              41001
 #define ID_EDIT_COPY_APPEND             41002


Index: /trunk/res/cedt_us.rc
===================================================================
--- /trunk/res/cedt_us.rc   (revision 238)
+++ /trunk/res/cedt_us.rc   (working copy)
@@ -300,6 +300,7 @@
         MENUITEM "Open &Template...\tAlt+Shift+O", ID_FILE_OPEN_TEMPLATE
         MENUITEM SEPARATOR
         MENUITEM "&Close\tCtrl+F4",             ID_FILE_CLOSE
+        MENUITEM "Close &Other",                ID_FILE_CLOSE_OTHERS
         MENUITEM "Clos&e All",                  ID_FILE_CLOSE_ALL
         MENUITEM SEPARATOR
         MENUITEM "&Reload",                     ID_FILE_RELOAD
@@ -718,6 +719,7 @@
     POPUP "TAB_ITEM"
     BEGIN
         MENUITEM "&Close",                      ID_WINDOW_CLOSE
+        MENUITEM "Close &Other",                ID_FILE_CLOSE_OTHERS
         MENUITEM "Clos&e All",                  ID_FILE_CLOSE_ALL
         MENUITEM SEPARATOR
         MENUITEM "&Reload",                     ID_FILE_RELOAD
@@ -2021,6 +2023,7 @@
     ID_SYNTAX_RELOAD        "Reload syntaxes & active document\nReload Syntaxes"
     ID_FILE_OPEN_TEMPLATE   "Open an existing document template\nOpen Template"
     ID_FILE_CLOSE_ALL       "Close all open files\nClose All"
+    ID_FILE_CLOSE_OTHERS    "Close all other files\nClose Other"
     ID_FILE_RELOAD_AS       "Reload the active document using a converter\nReload As"
 END
 
Index: /trunk/src/cedtapp.h
===================================================================
--- /trunk/src/cedtapp.h   (revision 238)
+++ /trunk/src/cedtapp.h   (working copy)
@@ -232,6 +232,7 @@
    afx_msg void OnViewSetLineSpacing();
    afx_msg void OnViewSetTabSize();
    afx_msg void OnFileCloseAll();
+   afx_msg void OnFileCloseOthers();
    afx_msg void OnDocuSyntaxCustomize();
    afx_msg void OnViewColumnMarkers();
    afx_msg void OnSearchFindInFiles();

Index: /trunk/src/cedtapp.cpp
===================================================================
--- /trunk/src/cedtapp.cpp   (revision 238)
+++ /trunk/src/cedtapp.cpp   (working copy)
@@ -79,6 +79,7 @@
    ON_COMMAND(ID_VIEW_SET_LINE_SPACING, OnViewSetLineSpacing)
    ON_COMMAND(ID_VIEW_SET_TAB_SIZE, OnViewSetTabSize)
    ON_COMMAND(ID_FILE_CLOSE_ALL, OnFileCloseAll)
+   ON_COMMAND(ID_FILE_CLOSE_OTHERS, OnFileCloseOthers)
    ON_COMMAND(ID_DOCU_SYNTAX_CUSTOMIZE, OnDocuSyntaxCustomize)
    ON_COMMAND(ID_VIEW_COLUMN_MARKERS, OnViewColumnMarkers)
    ON_COMMAND(ID_SEARCH_FIND_IN_FILES, OnSearchFindInFiles)

Index: /trunk/src/cedtAppFile.cpp
===================================================================
--- /trunk/src/cedtAppFile.cpp   (revision 238)
+++ /trunk/src/cedtAppFile.cpp   (working copy)
@@ -114,7 +114,37 @@
    if( SaveAllModified() ) CloseAllDocuments(FALSE);
 }
 
+void CCedtApp::OnFileCloseOthers()
+{
+   // identifices the active window
+   CWnd * pActiveWindow = CWnd::GetFocus();
 
+   // loops over all windws
+   POSITION posDoc = GetFirstDocPosition();
+   while ( posDoc ) {
+      CDocument * pDoc = GetNextDoc( posDoc);
+      // Checks if it is the current document
+      POSITION posView = pDoc->GetFirstViewPosition();
+      bool found=false;
+      while( posView && ! found ) {
+         CView * pView = pDoc->GetNextView( posView );
+         if ( pActiveWindow == ( CWnd * ) pView ) {
+            found = true;
+         }
+      }
+      // if it is not the current document,save if necessary and close always
+      if ( ! found) {
+         if ( ! pDoc->SaveModified() ) {
+            // user cancelled the operation
+            return;
+         } else {
+            pDoc -> OnCloseDocument();
+         }
+      }
+   }
+}
+
+
 BOOL CCedtApp::ReloadLastWorkingFiles()
 {
    if (m_bProjectLoaded) {


It has been tested on VS2008 STD.

All comments are welcome.

Best regards,

Zara
Logged
pn8830
Global Moderator
Jeweller
*****
Posts: 252



« Reply #1 on: May 06, 2008, 01:10:42 am »

Hello,
I tried to apply this patch but had some issues. If you could get Tortoise SVN and create a patch with it that would be great.
Thank,
PN
Logged

Entities should not be multiplied beyond necessity
zara
Prospector
*
Posts: 5


« Reply #2 on: May 06, 2008, 05:30:26 am »

The patch has been generated by TortoiseSVN, but mayebe there are some problems with the format. As soon as I get to the computer at work, I will generate the diff with SVN itself.

Best regards,

zara

(Later...)

Got it, it should work:

<DIFF>
Index: CrimsonEditor/trunk/src/cedtapp.h
===================================================================
--- CrimsonEditor/trunk/src/cedtapp.h   (revision 238)
+++ CrimsonEditor/trunk/src/cedtapp.h   (working copy)
@@ -232,6 +232,7 @@
    afx_msg void OnViewSetLineSpacing();
    afx_msg void OnViewSetTabSize();
    afx_msg void OnFileCloseAll();
+   afx_msg void OnFileCloseOthers();
    afx_msg void OnDocuSyntaxCustomize();
    afx_msg void OnViewColumnMarkers();
    afx_msg void OnSearchFindInFiles();
Index: CrimsonEditor/trunk/src/cedtAppFile.cpp
===================================================================
--- CrimsonEditor/trunk/src/cedtAppFile.cpp   (revision 238)
+++ CrimsonEditor/trunk/src/cedtAppFile.cpp   (working copy)
@@ -114,7 +114,37 @@
    if( SaveAllModified() ) CloseAllDocuments(FALSE);
 }
 
+void CCedtApp::OnFileCloseOthers()
+{
+   // identifices the active window
+   CWnd * pActiveWindow = CWnd::GetFocus();
 
+   // loops over all windws
+   POSITION posDoc = GetFirstDocPosition();
+   while ( posDoc ) {
+      CDocument * pDoc = GetNextDoc( posDoc);
+      // Checks if it is the current document
+      POSITION posView = pDoc->GetFirstViewPosition();
+      bool found=false;
+      while( posView && ! found ) {
+         CView * pView = pDoc->GetNextView( posView );
+         if ( pActiveWindow == ( CWnd * ) pView ) {
+            found = true;
+         }
+      }
+      // if it is not the current document,save if necessary and close always
+      if ( ! found) {
+         if ( ! pDoc->SaveModified() ) {
+            // user cancelled the operation
+            return;
+         } else {
+            pDoc -> OnCloseDocument();
+         }
+      }
+   }
+}
+
+
 BOOL CCedtApp::ReloadLastWorkingFiles()
 {
    if (m_bProjectLoaded) {
Index: CrimsonEditor/trunk/src/cedtapp.cpp
===================================================================
--- CrimsonEditor/trunk/src/cedtapp.cpp   (revision 238)
+++ CrimsonEditor/trunk/src/cedtapp.cpp   (working copy)
@@ -79,6 +79,7 @@
    ON_COMMAND(ID_VIEW_SET_LINE_SPACING, OnViewSetLineSpacing)
    ON_COMMAND(ID_VIEW_SET_TAB_SIZE, OnViewSetTabSize)
    ON_COMMAND(ID_FILE_CLOSE_ALL, OnFileCloseAll)
+   ON_COMMAND(ID_FILE_CLOSE_OTHERS, OnFileCloseOthers)
    ON_COMMAND(ID_DOCU_SYNTAX_CUSTOMIZE, OnDocuSyntaxCustomize)
    ON_COMMAND(ID_VIEW_COLUMN_MARKERS, OnViewColumnMarkers)
    ON_COMMAND(ID_SEARCH_FIND_IN_FILES, OnSearchFindInFiles)
Index: CrimsonEditor/trunk/res/cedt_us.rc
===================================================================
--- CrimsonEditor/trunk/res/cedt_us.rc   (revision 238)
+++ CrimsonEditor/trunk/res/cedt_us.rc   (working copy)
@@ -300,6 +300,7 @@
         MENUITEM "Open &Template...\tAlt+Shift+O", ID_FILE_OPEN_TEMPLATE
         MENUITEM SEPARATOR
         MENUITEM "&Close\tCtrl+F4",             ID_FILE_CLOSE
+        MENUITEM "Close &Other",                ID_FILE_CLOSE_OTHERS
         MENUITEM "Clos&e All",                  ID_FILE_CLOSE_ALL
         MENUITEM SEPARATOR
         MENUITEM "&Reload",                     ID_FILE_RELOAD
@@ -718,6 +719,7 @@
     POPUP "TAB_ITEM"
     BEGIN
         MENUITEM "&Close",                      ID_WINDOW_CLOSE
+        MENUITEM "Close &Other",                ID_FILE_CLOSE_OTHERS
         MENUITEM "Clos&e All",                  ID_FILE_CLOSE_ALL
         MENUITEM SEPARATOR
         MENUITEM "&Reload",                     ID_FILE_RELOAD
@@ -2021,6 +2023,7 @@
     ID_SYNTAX_RELOAD        "Reload syntaxes & active document\nReload Syntaxes"
     ID_FILE_OPEN_TEMPLATE   "Open an existing document template\nOpen Template"
     ID_FILE_CLOSE_ALL       "Close all open files\nClose All"
+    ID_FILE_CLOSE_OTHERS    "Close all other files\nClose Other"
     ID_FILE_RELOAD_AS       "Reload the active document using a converter\nReload As"
 END
 
Index: CrimsonEditor/trunk/res/resource.h
===================================================================
--- CrimsonEditor/trunk/res/resource.h   (revision 238)
+++ CrimsonEditor/trunk/res/resource.h   (working copy)
@@ -582,6 +582,7 @@
 #define ID_FILE_CLOSE_ALL               40007
 #define ID_FILE_RELOAD_AS               40008
 #define ID_SYNTAX_RELOAD                40009
+#define ID_FILE_CLOSE_OTHERS            40010
 #define ID_EDIT_DELETE                  41000
 #define ID_EDIT_CUT_APPEND              41001
 #define ID_EDIT_COPY_APPEND             41002

</DIFF>
« Last Edit: May 06, 2008, 06:21:28 am by zara » Logged
Pvt_Ryan
Master Jeweller
******
Posts: 422



WWW
« Reply #3 on: May 06, 2008, 10:01:23 am »

I'll try and apply the patch when I get home and if everything works ok I will commit it (Although looking at the code it seems straight forward enough)

Thanks very much for implementing this feature.
Logged
pn8830
Global Moderator
Jeweller
*****
Posts: 252



« Reply #4 on: May 06, 2008, 03:46:31 pm »

Ok.. I should have been more clear... posting a patch as an attachment would help Smiley I tried to work on it yesterday but it only worked for resourse.h and cedt_us.rc
PN
Logged

Entities should not be multiplied beyond necessity
zara
Prospector
*
Posts: 5


« Reply #5 on: May 07, 2008, 06:48:53 am »

I hope it works this time...

To be sincere, although I work with SVN regularly, this is the first time I use the patching feature. Seems nice, anyhow.

Best regards,

Zara

* patch.txt (4.24 KB - downloaded 460 times.)
Logged
Pvt_Ryan
Master Jeweller
******
Posts: 422



WWW
« Reply #6 on: May 10, 2008, 12:17:17 am »

Committted rev 239
Logged
pn8830
Global Moderator
Jeweller
*****
Posts: 252



« Reply #7 on: May 11, 2008, 12:10:44 am »

Thank you! Docs updated. Update binaries?
PN
« Last Edit: May 11, 2008, 03:21:05 pm by pn8830 » Logged

Entities should not be multiplied beyond necessity
Arantor
Site Administrator
Administrator
Master Jeweller
*****
Posts: 618



« Reply #8 on: May 11, 2008, 12:53:44 am »

BTW I'll add them to the download area, once posted.
Logged

"Cleverly disguised as a responsible adult!"
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.137 seconds with 18 queries.