mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-02 13:09:27 +00:00
Now right-clicking a tab shows a popup-menu with useful options for the document.
+ Added OpenInFolder and OpenWithApp commands. + Added Launcher::openFolder. + Added document_tab_popup_menu.
This commit is contained in:
parent
e281fc4a41
commit
ff481003c8
@ -330,7 +330,14 @@
|
||||
<item command="About" text="&About" />
|
||||
</menu>
|
||||
</menu>
|
||||
|
||||
|
||||
<menu id="document_tab_popup">
|
||||
<item command="CloseFile" text="&Close" />
|
||||
<separator />
|
||||
<item command="OpenInFolder" text="Open In &Folder" />
|
||||
<item command="OpenWithApp" text="Open With Associated &Application" />
|
||||
</menu>
|
||||
|
||||
<menu id="layer_popup">
|
||||
<item command="LayerProperties" text="&Properties..." />
|
||||
<separator />
|
||||
|
@ -139,6 +139,8 @@ add_library(aseprite-library
|
||||
commands/cmd_new_layer.cpp
|
||||
commands/cmd_new_layer_set.cpp
|
||||
commands/cmd_open_file.cpp
|
||||
commands/cmd_open_in_folder.cpp
|
||||
commands/cmd_open_with_app.cpp
|
||||
commands/cmd_options.cpp
|
||||
commands/cmd_palette_editor.cpp
|
||||
commands/cmd_paste.cpp
|
||||
|
24
src/app.cpp
24
src/app.cpp
@ -491,17 +491,29 @@ int app_get_color_to_clear_layer(Layer* layer)
|
||||
|
||||
void AppTabsDelegate::clickTab(Tabs* tabs, void* data, int button)
|
||||
{
|
||||
Document* document = (Document*)data;
|
||||
Document* document = reinterpret_cast<Document*>(data);
|
||||
|
||||
// put as current sprite
|
||||
set_document_in_more_reliable_editor(document);
|
||||
|
||||
// middle-button: close the sprite
|
||||
if (data && (button & 4)) {
|
||||
Command* close_file_cmd =
|
||||
CommandsModule::instance()->getCommandByName(CommandId::CloseFile);
|
||||
if (document) {
|
||||
Context* context = UIContext::instance();
|
||||
context->updateFlags();
|
||||
|
||||
UIContext::instance()->executeCommand(close_file_cmd, NULL);
|
||||
// right-button: popup-menu
|
||||
if (button & 2) {
|
||||
Menu* popup_menu = get_document_tab_popup_menu();
|
||||
if (popup_menu != NULL) {
|
||||
popup_menu->showPopup(jmouse_x(0), jmouse_y(0));
|
||||
}
|
||||
}
|
||||
// middle-button: close the sprite
|
||||
else if (button & 4) {
|
||||
Command* close_file_cmd =
|
||||
CommandsModule::instance()->getCommandByName(CommandId::CloseFile);
|
||||
|
||||
context->executeCommand(close_file_cmd, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
63
src/commands/cmd_open_in_folder.cpp
Normal file
63
src/commands/cmd_open_in_folder.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "commands/command.h"
|
||||
#include "document.h"
|
||||
#include "document_wrappers.h"
|
||||
#include "context.h"
|
||||
#include "launcher.h"
|
||||
|
||||
class OpenInFolderCommand : public Command
|
||||
{
|
||||
public:
|
||||
OpenInFolderCommand();
|
||||
Command* clone() { return new OpenInFolderCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context) OVERRIDE;
|
||||
void onExecute(Context* context) OVERRIDE;
|
||||
};
|
||||
|
||||
OpenInFolderCommand::OpenInFolderCommand()
|
||||
: Command("OpenInFolder",
|
||||
"Open In Folder",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool OpenInFolderCommand::onEnabled(Context* context)
|
||||
{
|
||||
const ActiveDocumentReader document(context);
|
||||
return document && document->isAssociatedToFile();
|
||||
}
|
||||
|
||||
void OpenInFolderCommand::onExecute(Context* context)
|
||||
{
|
||||
Launcher::openFolder(context->getActiveDocument()->getFilename());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CommandFactory
|
||||
|
||||
Command* CommandFactory::createOpenInFolderCommand()
|
||||
{
|
||||
return new OpenInFolderCommand;
|
||||
}
|
63
src/commands/cmd_open_with_app.cpp
Normal file
63
src/commands/cmd_open_with_app.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/* ASE - Allegro Sprite Editor
|
||||
* Copyright (C) 2001-2011 David Capello
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "commands/command.h"
|
||||
#include "document.h"
|
||||
#include "document_wrappers.h"
|
||||
#include "context.h"
|
||||
#include "launcher.h"
|
||||
|
||||
class OpenWithAppCommand : public Command
|
||||
{
|
||||
public:
|
||||
OpenWithAppCommand();
|
||||
Command* clone() { return new OpenWithAppCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context) OVERRIDE;
|
||||
void onExecute(Context* context) OVERRIDE;
|
||||
};
|
||||
|
||||
OpenWithAppCommand::OpenWithAppCommand()
|
||||
: Command("OpenWithApp",
|
||||
"Open With Associated Application",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool OpenWithAppCommand::onEnabled(Context* context)
|
||||
{
|
||||
const ActiveDocumentReader document(context);
|
||||
return document && document->isAssociatedToFile();
|
||||
}
|
||||
|
||||
void OpenWithAppCommand::onExecute(Context* context)
|
||||
{
|
||||
Launcher::openFile(context->getActiveDocument()->getFilename());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CommandFactory
|
||||
|
||||
Command* CommandFactory::createOpenWithAppCommand()
|
||||
{
|
||||
return new OpenWithAppCommand;
|
||||
}
|
@ -71,6 +71,8 @@ FOR_EACH_COMMAND(NewFrame)
|
||||
FOR_EACH_COMMAND(NewLayer)
|
||||
FOR_EACH_COMMAND(NewLayerSet)
|
||||
FOR_EACH_COMMAND(OpenFile)
|
||||
FOR_EACH_COMMAND(OpenInFolder)
|
||||
FOR_EACH_COMMAND(OpenWithApp)
|
||||
FOR_EACH_COMMAND(Options)
|
||||
FOR_EACH_COMMAND(PaletteEditor)
|
||||
FOR_EACH_COMMAND(Paste)
|
||||
|
@ -18,12 +18,47 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "base/exception.h"
|
||||
#include "gui/alert.h"
|
||||
#include "launcher.h"
|
||||
|
||||
#if defined ALLEGRO_WINDOWS
|
||||
#define BITMAP WINDOWS_BITMAP
|
||||
#include <windows.h>
|
||||
#define BITMAP WINDOWS_BITMAP
|
||||
#include <windows.h>
|
||||
|
||||
static void win32_shell_execute(const char* verb, const char* file, const char* params)
|
||||
{
|
||||
SHELLEXECUTEINFO sh;
|
||||
ZeroMemory((LPVOID)&sh, sizeof(sh));
|
||||
sh.cbSize = sizeof(sh);
|
||||
sh.fMask = SEE_MASK_DEFAULT;
|
||||
sh.lpVerb = verb;
|
||||
sh.lpFile = file;
|
||||
sh.lpParameters = params;
|
||||
sh.nShow = SW_SHOWNORMAL;
|
||||
|
||||
if (!ShellExecuteEx(&sh)) {
|
||||
int ret = GetLastError();
|
||||
if (ret != 0) {
|
||||
DWORD flags =
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS;
|
||||
LPSTR msgbuf;
|
||||
|
||||
if (FormatMessageA(flags, NULL, ret,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
reinterpret_cast<LPSTR>(&msgbuf),
|
||||
0, NULL)) {
|
||||
Alert::show("Problem<<Cannot open:<<%s<<%s||&Close", file, msgbuf);
|
||||
LocalFree(msgbuf);
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void Launcher::openUrl(const std::string& url)
|
||||
@ -37,8 +72,8 @@ void Launcher::openFile(const std::string& file)
|
||||
|
||||
#if defined ALLEGRO_WINDOWS
|
||||
|
||||
ShellExecute(NULL, "open", file.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
ret = 0; // TODO Use ShellExecuteEx to know the return value
|
||||
win32_shell_execute("open", file.c_str(), NULL);
|
||||
ret = 0;
|
||||
|
||||
#elif defined ALLEGRO_MACOSX
|
||||
|
||||
@ -53,3 +88,20 @@ void Launcher::openFile(const std::string& file)
|
||||
if (ret != 0)
|
||||
Alert::show("Problem<<Cannot open:<<%s||&Close", file.c_str());
|
||||
}
|
||||
|
||||
void Launcher::openFolder(const std::string& file)
|
||||
{
|
||||
#if defined ALLEGRO_WINDOWS
|
||||
|
||||
win32_shell_execute(NULL, "explorer", ("/e,/select,\"" + file + "\"").c_str());
|
||||
|
||||
#elif defined ALLEGRO_MACOSX
|
||||
|
||||
Alert::show("Problem<<This command is not supported on Mac OS X||&Close");
|
||||
|
||||
#else // Linux
|
||||
|
||||
Alert::show("Problem<<This command is not supported on Linux||&Close");
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ class Launcher
|
||||
public:
|
||||
static void openUrl(const std::string& url);
|
||||
static void openFile(const std::string& file);
|
||||
static void openFolder(const std::string& file);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -42,6 +42,7 @@
|
||||
static Menu* root_menu;
|
||||
|
||||
static MenuItem* recent_list_menuitem;
|
||||
static Menu* document_tab_popup_menu;
|
||||
static Menu* layer_popup_menu;
|
||||
static Menu* frame_popup_menu;
|
||||
static Menu* cel_popup_menu;
|
||||
@ -56,6 +57,7 @@ static void apply_shortcut_to_menuitems_with_command(Menu* menu, Command* comman
|
||||
int init_module_rootmenu()
|
||||
{
|
||||
root_menu = NULL;
|
||||
document_tab_popup_menu = NULL;
|
||||
layer_popup_menu = NULL;
|
||||
frame_popup_menu = NULL;
|
||||
cel_popup_menu = NULL;
|
||||
@ -68,6 +70,7 @@ int init_module_rootmenu()
|
||||
void exit_module_rootmenu()
|
||||
{
|
||||
delete root_menu;
|
||||
delete document_tab_popup_menu;
|
||||
delete layer_popup_menu;
|
||||
delete frame_popup_menu;
|
||||
delete cel_popup_menu;
|
||||
@ -77,6 +80,7 @@ void exit_module_rootmenu()
|
||||
Menu* get_root_menu() { return root_menu; }
|
||||
|
||||
MenuItem* get_recent_list_menuitem() { return recent_list_menuitem; }
|
||||
Menu* get_document_tab_popup_menu() { return document_tab_popup_menu; }
|
||||
Menu* get_layer_popup_menu() { return layer_popup_menu; }
|
||||
Menu* get_frame_popup_menu() { return frame_popup_menu; }
|
||||
Menu* get_cel_popup_menu() { return cel_popup_menu; }
|
||||
@ -93,6 +97,7 @@ static int load_root_menu()
|
||||
// create a new empty-menu
|
||||
root_menu = NULL;
|
||||
recent_list_menuitem = NULL;
|
||||
document_tab_popup_menu = NULL;
|
||||
layer_popup_menu = NULL;
|
||||
frame_popup_menu = NULL;
|
||||
cel_popup_menu = NULL;
|
||||
@ -115,6 +120,7 @@ static int load_root_menu()
|
||||
|
||||
PRINTF("Main menu loaded.\n");
|
||||
|
||||
document_tab_popup_menu = load_menu_by_id(handle, "document_tab_popup");
|
||||
layer_popup_menu = load_menu_by_id(handle, "layer_popup");
|
||||
frame_popup_menu = load_menu_by_id(handle, "frame_popup");
|
||||
cel_popup_menu = load_menu_by_id(handle, "cel_popup");
|
||||
|
@ -38,6 +38,7 @@ void exit_module_rootmenu();
|
||||
Menu* get_root_menu();
|
||||
|
||||
MenuItem* get_recent_list_menuitem();
|
||||
Menu* get_document_tab_popup_menu();
|
||||
Menu* get_layer_popup_menu();
|
||||
Menu* get_frame_popup_menu();
|
||||
Menu* get_cel_popup_menu();
|
||||
|
Loading…
Reference in New Issue
Block a user